# -*- coding: utf-8 -*-

# 获取引擎服务端API的模块
import mod.server.extraServerApi as serverApi

import random

# 获取引擎服务端System的基类，System都要继承于ServerSystem来调用相关函数
ServerSystem = serverApi.GetServerSystemCls()
# 获取组件工厂，用来创建组件
compFactory = serverApi.GetEngineCompFactory()

import time


# 在modMain中注册的Server System类
class TutorialServerSystem(ServerSystem):
    die_times = -1
    MyNotice = "§l§6【欢迎游玩末地龙魂】\n§l§c加群可一起交流、学习指令知识\n§l§2 1.初云杯大赛开始报名，快入群一起PVP~\n§l§4 2.地图作者（我是初云）已开启直播，各大平台直接搜索即可~\n§l§3 3.若发现BUG或者有更好的建议，欢迎入群提出~\n§l§8地图更新时间：2023年1月31日"
    map_op = ["初云如梦", "我是初云", "我是初云工作室", "我是小初云"]
    title_yellow = ["初云如梦", "我是初云", "我是初云工作室", "MCY初云联赛", "我是小初云"]
    title_purple = {
        "No561164833": "最佳战术奖",
        "史蒂夫125436": "最佳弓箭手",
        "hipor我是榴莲": "最佳参与奖",
        "98岁扶床对抗": "最佳近战奖",
        "铁板高光": "最佳近战奖",
        "星之梦燃": "暗夜杀手奖",
        "皮卡皮qvq": "六之天王奖",
        "摘星我去": "地图守护者",
        "LXHcomet": "地图守护者"
    }
    title_red = ["XONF", "爱看戏的小九茗", "aim752", "小本乐鑫", "Y红钻飞凤Y", "挨打的是我8", "98岁扶床对抗", "MS战团x谢白", "一觉睡不醒", "啊啊啊对对对", "陈天",
                 "MF秋悸呀", "萌新_小作者", "突企图", "aaa懒茗", "smainnly", "下楼梯的冷冽鸽子", "铁板高光", "西门天蓝魔与神", "大脸猫多多", "星之梦燃", "乄O杰O乄",
                 "骄傲驴寻宝", "大力出奇迹8572", "有树枝的爱坤粉", "皮卡皮qvq", "皓烨——L", "归零计划爱吃糖", "苦味盖运聪下楼梯", "小剑客ya", "tEXwuSYe",
                 "卧室笑柯哀",
                 "图佟5", "你个荒古光", "消丑不消愁", "斗安户", "ungdertale冥", "东方曼倩之星期", "SP毒辣", "2753943930",
                 "勤奋的风史雨化", "我独特之人"]
    title_black = ["燓割歌", "图佟5", "练吉他的勤奋芒果", "李白当大白", "方便对方", "老王我无了"]
    title_green = ["2753943930", "云柄", "hipro我是榴莲"]
    map_entityId = {}
    all_entityId = []

    recover_tp_team = ""
    recover_tp_id = 0
    recover_status_id = 0

    ver = "0.40"

    suoquan_r = 330
    suoquan_sw = False

    match_scends = 60
    event_all_speed = False
    event_all_jump = False
    event_all_power = False
    win_team = ""

    tick_s_30 = 0

    fix_y = 115

    dr_times = 0
    dr_switch = False
    hide_id = 0

    tick = 0
    tick_s = 0
    tick_s_5 = 0
    tick_s_59 = 0
    tick_m = 0
    tick_s_10 = 0
    tick_ss_15 = 0

    time_laters = []

    BW_bed_orange = False
    BW_bed_blue = False
    BW_bed_green = False
    BW_bed_purple = False

    tick_iron_ingot = 0
    tick_gold_ingot = 0
    tick_diamond = 0
    tick_emerald = 0

    guanzhanPlayer = []
    match_switch = False
    event_index_all = 0

    bedwar_teamslist_blue_id = []
    bedwar_teamslist_green_id = []
    bedwar_teamslist_orange_id = []
    bedwar_teamslist_purple_id = []

    bedwar_player_list = []
    dead_list = []
    BW_match_playerlist = []
    BW_aev_playerlist = []
    playerlist_new = []
    com_safe_switch = True

    bedwar_switch = False  # 起床战争比赛开关
    bedwar_times = 0  # 起床战争总计时

    bedwar_restart = False

    create_sw = False
    create_sw_str = 0

    event_list_tick = []

    bedwar_config_res_fresh_xyzs = {
        "iron_ingot": [[93, 68, 143], [91, 68, 143], [89, 68, 143],
                       [-96, 68, 140], [-98, 68, 140], [-100, 68, 140],
                       [-64, 68, -143], [-62, 68, -143], [-60, 68, -143],
                       [94, 70, -139], [96, 70, -139], [98, 70, -139]
                       ],
        "gold_ingot": [[63, 68, -26], [37, 68, -58], [0, 68, -68], [0, 68, -68], [-38, 68, -59], [-65, 68, -21],
                       [-65, 68, 20], [-38, 68, 57], [-1, 68, 67], [37, 68, 57], [63, 68, 25]],
        "diamond": [[-12, 92, 39], [14, 92, 39], [33, 92, 23], [33, 92, -26], [12, 92, -40], [-14, 92, -40],
                    [-34, 92, -24], [-42, 92, 1], [-34, 92, 25]
                    ],
        "emerald": [[0, 58, 0], [100, 51, 0], [-5, 51, 0]]
    }  # 资源点刷新位置
    bedwar_config_res_fresh_times = {
        "iron_ingot": [2, 2],
        "gold_ingot": [20, 10],
        "diamond": [30, 30],
        "emerald": [60, 30]
    }  # 资源点刷新时间
    bedwar_event_times = [{
        "id": 1,
        "name": "全体速度加成",
        "times": 300
    }, {
        "id": 2,
        "name": "刷新末影龙",
        "times": 600
    }, {
        "id": 3,
        "name": "全体跳跃加成",
        "times": 900
    }, {
        "id": 4,
        "name": "刷新末影龙",
        "times": 1200
    }, {
        "id": 5,
        "name": "全体力量加成",
        "times": 1500
    }, {
        "id": 6,
        "name": "刷新末影龙",
        "times": 1800
    }, {
        "id": 7,
        "name": "所有床自毁并缩圈",
        "times": 2100
    }, {
        "id": 8,
        "name": "所有人随机传送",
        "times": 2400
    }
    ]
    bedwar_res_clone = {"iron_ingot": [-3, 1, -5],
                        "gold_ingot": [-2, 2, -6],
                        "diamond": [-1, 1, -5],
                        "emerald": [0, 2, -6],
                        "drgon": [1, 1, -5]
                        }

    can_des = ['minecraft:wool', 'minecraft:ladder', 'minecraft:sandstone', 'minecraft:end_stone',
               'minecraft:nether_brick', 'minecraft:packed_ice', 'minecraft:oak_stairs', 'minecraft:planks',
               'minecraft:emerald_block', 'minecraft:chest', 'minecraft:ender_chest', 'minecraft:slime',
               'minecraft:bed']

    commands_player_list = []

    playerlist = []

    # MyNotice = "§l§6【比赛喜报】狙击作战百人国庆PVP比赛中：\n§l§6★恭喜初云如梦夺冠\n§l§6★No561164833获得第二名\n§l§6★史蒂夫125436获得第三名\n§l§6欢迎各位入群报名参赛"

    # ServerSystem的初始化函数
    def __init__(self, namespace, systemName):
        # 首先调用父类的初始化函数
        super(TutorialServerSystem, self).__init__(namespace, systemName)
        print "===== TutorialServerSystem init ====="
        print "===== 2023年1月16日12点31分 ====="
        # 初始时调用监听函数监听事件
        httpComp = compFactory.CreateHttp(serverApi.GetLevelId())
        # 返回来自开发者平台的运营管理配置中配置的数据。注意：每次在开发者平台提交的JSON配置数据会顶替掉上一次的配置信息。
        httpComp.LobbyGetStorage(self.callback_c, 0, ['op_config'])
        self.ListenEvent()
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        opLevel = 1
        suc = comp.SetDefaultPlayerPermissionLevel(opLevel)

        print ("###serverApi", namespace, systemName)
        print "SetDefaultPlayerPermissionLevel to {} suc={}".format(opLevel, suc)

    def BroadCastEventTest(self, g):
        self.BroadcastToAllClient("data_get", g)
        print ("###BroadcastToAllClient", g)

    # 玩家请求执行指令时触发
    def OnCommandEvent(self, args):
        print "【指令控制系统：2023年1月16日15点03分更新修复】"
        print "===== 有玩家使用指令 ====="
        print args
        playerId = args['entityId']
        playername = self.map_entityId[playerId]
        print playerId
        print playername
        num = len(self.map_op)
        print self.map_op
        for i in self.map_op:
            num -= 1
            print num
            if playername == i:
                args['cancel'] = False
                print "===== 是管理员。可用指令 ====="
                break
            elif num == 0:
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§c仅管理员可用命令！"}]}', playerId, False)
                args['cancel'] = True
                print "===== 非管理员，退回指令 ====="

    def cb(self, data):
        if data:
            newData = {i["key"]: i["value"] for i in data["entity"]["data"]}
            scores_c = newData["score_ss1"]

            if (len(self.scores_c) != 0):
                self.scores_cloud = {self.scores_cloud_playerId: scores_c}
                comp = serverApi.GetEngineCompFactory().CreateHttp(serverApi.GetLevelId())
                comp.LobbySetStorageAndUserItem(self.cb_a, self.scores_cloud_uid, "", self.getter)
            else:
                print "===== 数据错误 ====="
        else:
            print "===== 获取数据失败 ====="

    def cb_a(self, data):
        if data:
            # 更新本地数据
            newData = {i["key"]: i["value"] for i in data["entity"]["data"]}
            print (self.scores_cloud_uid, newData["score_ss1"])
        else:
            print "===== 设置数据失败 ====="

    def getter(self):
        return [
            {
                "key": "score_ss1",
                "value": self.scores_cloud[self.scores_cloud_playerId] + self.score_local
            }
        ]

    # 监听函数，用于定义和监听函数。函数名称除了强调的其他都是自取的，这个函数也是。
    def ListenEvent(self):

        self.ListenForEvent(serverApi.GetEngineNamespace(),
                            serverApi.GetEngineSystemName(), "ServerChatEvent", self,
                            self.OnServerChat)  # 玩家发送聊天信息时触发

        self.ListenForEvent(serverApi.GetEngineNamespace(),
                            serverApi.GetEngineSystemName(), "PlayerJoinMessageEvent", self,
                            self.OnPlayerJoinMessageEvent)  # 玩家登录提示文字时服务端抛出的事件

        self.ListenForEvent(serverApi.GetEngineNamespace(),
                            serverApi.GetEngineSystemName(), "PlayerAttackEntityEvent", self,
                            self.OnPlayerAttackEntityEvent)  # 当玩家攻击时触发该事件

        self.ListenForEvent(serverApi.GetEngineNamespace(),
                            serverApi.GetEngineSystemName(), "CommandEvent", self,
                            self.OnCommandEvent)  # 玩家请求执行指令时触发

        self.ListenForEvent(serverApi.GetEngineNamespace(),
                            serverApi.GetEngineSystemName(), "OnScriptTickServer", self,
                            self.OnScriptTickServer)  # 服务器tick时触发

        self.ListenForEvent(serverApi.GetEngineNamespace(),
                            serverApi.GetEngineSystemName(), "PlayerTrySleepServerEvent", self,
                            self.PlayerTrySleepServerEvent)  # 玩家尝试使用床睡觉

        self.ListenForEvent(serverApi.GetEngineNamespace(),
                            serverApi.GetEngineSystemName(), "PlayerDieEvent", self,
                            self.PlayerDieEvent)

        self.ListenForEvent(serverApi.GetEngineNamespace(),
                            serverApi.GetEngineSystemName(), "DimensionChangeServerEvent", self,
                            self.DimensionChangeServerEvent)

        self.ListenForEvent(serverApi.GetEngineNamespace(),
                            serverApi.GetEngineSystemName(), "ServerItemTryUseEvent", self,
                            self.ServerItemTryUseEvent)  # 玩家点击右键尝试使用物品时服务端抛出的事件

        self.ListenForEvent(serverApi.GetEngineNamespace(),
                            serverApi.GetEngineSystemName(), "ServerPlayerTryDestroyBlockEvent", self,
                            self.ServerPlayerTryDestroyBlockEvent)

        # self.ListenForEvent(serverApi.GetEngineNamespace(),
        #                     serverApi.GetEngineSystemName(), "LoadServerAddonScriptsAfter", self,
        #                     self.LoadServerAddonScriptsAfter)

        # # 在自定义的ServerSystem中监听引擎的事件ServerChatEvent，回调函数为OnServerChat
        # self.ListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(), "ServerChatEvent", self,
        #                     self.OnServerChat)

        self.ListenForEvent(serverApi.GetEngineNamespace(),
                            serverApi.GetEngineSystemName(), "OnCommandOutputServerEvent", self,
                            self.OnCommandOutputServerEvent)

        self.ListenForEvent(serverApi.GetEngineNamespace(),
                            serverApi.GetEngineSystemName(), "MobDieEvent", self,
                            self.MobDieEvent)

        self.ListenForEvent(serverApi.GetEngineNamespace(),
                            serverApi.GetEngineSystemName(), "ServerPlayerTryTouchEvent", self,
                            self.ServerPlayerTryTouchEvent)

        self.ListenForEvent(serverApi.GetEngineNamespace(),
                            serverApi.GetEngineSystemName(), "PlayerLeftMessageServerEvent", self,
                            self.PlayerLeftMessageServerEvent)

    # 反监听函数，用于反监听事件，在代码中有创建注册就对应了销毁反注册是一个好的编程习惯，不要依赖引擎来做这些事。
    def UnListenEvent(self):
        self.UnListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(), "ServerChatEvent", self,
                              self.OnServerChat)

        self.UnListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(), "PlayerJoinMessageEvent",
                              self, self.OnPlayerJoinMessageEvent)

        self.UnListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(),
                              "PlayerAttackEntityEvent",
                              self, self.OnPlayerAttackEntityEvent)

        self.UnListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(),
                              "CommandEvent",
                              self, self.OnCommandEvent)

        self.UnListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(),
                              "OnScriptTickServer",
                              self, self.OnScriptTickServer)

        self.UnListenForEvent(serverApi.GetEngineNamespace(),
                              serverApi.GetEngineSystemName(), "PlayerTrySleepServerEvent", self,
                              self.PlayerTrySleepServerEvent)

        self.UnListenForEvent(serverApi.GetEngineNamespace(),
                              serverApi.GetEngineSystemName(), "DimensionChangeServerEvent", self,
                              self.DimensionChangeServerEvent)

        self.UnListenForEvent(serverApi.GetEngineNamespace(),
                              serverApi.GetEngineSystemName(), "ServerItemTryUseEvent", self,
                              self.ServerItemTryUseEvent)

        self.UnListenForEvent(serverApi.GetEngineNamespace(),
                              serverApi.GetEngineSystemName(), "OnCommandOutputServerEvent", self,
                              self.OnCommandOutputServerEvent)

        self.UnListenForEvent(serverApi.GetEngineNamespace(),
                              serverApi.GetEngineSystemName(), "ServerPlayerTryDestroyBlockEvent", self,
                              self.ServerPlayerTryDestroyBlockEvent)

        self.UnListenForEvent(serverApi.GetEngineNamespace(),
                              serverApi.GetEngineSystemName(), "MobDieEvent", self,
                              self.MobDieEvent)

        self.UnListenForEvent(serverApi.GetEngineNamespace(),
                              serverApi.GetEngineSystemName(), "ServerPlayerTryTouchEvent", self,
                              self.ServerPlayerTryTouchEvent)

        self.UnListenForEvent(serverApi.GetEngineNamespace(),
                              serverApi.GetEngineSystemName(), "PlayerLeftMessageServerEvent", self,
                              self.PlayerLeftMessageServerEvent)

        self.UnListenForEvent(serverApi.GetEngineNamespace(),
                              serverApi.GetEngineSystemName(), "ServerBlockUseEvent", self,
                              self.ServerBlockUseEvent)

        # self.UnListenForEvent(serverApi.GetEngineNamespace(),
        #                     serverApi.GetEngineSystemName(), "LoadServerAddonScriptsAfter", self,
        #                     self.LoadServerAddonScriptsAfter)

    # 玩家即将捡起物品时触发
    def ServerPlayerTryTouchEvent(self, args):

        playerId = args['playerId']
        entityId = args['entityId']
        itemDict = args['itemDict']

        print ("### ServerPlayerTryTouchEvent", playerId)

        for e in self.BW_aev_playerlist:
            print ("### ServerPlayerTryTouchEvent----e", e)
            if playerId == e:
                args['cancel'] = True

    # 告示牌点击事件
    def ServerBlockUseEvent(self, event):
        player_id = event['playerId']
        # 创建玩家的物品接口
        item_comp = serverApi.GetEngineCompFactory().CreateItem(player_id)
        # 获取玩家手持物品信息
        # .....
        # 获取事件里交互的方块类型
        block_name = event['blockName']

        if block_name == 'minecraft:standing_sign':
            # 创建方块信息接口
            block_comp = serverApi.GetEngineCompFactory().CreateBlockInfo(player_id)
            # 获取文告示牌字
            text1 = block_comp.GetSignBlockText((-115, 104, -135))
            text2 = block_comp.GetSignBlockText((-115, 104, -136))
            text3 = block_comp.GetSignBlockText((-115, 104, -137))

            if '点我加入' in text2:
                # 开始匹配
                if self.bedwar_switch == False:
                    comp = serverApi.GetEngineCompFactory().CreateDimension(player_id)
                    comp.ChangePlayerDimension(0, (-91, 108, -124))
                    self.BW_match_playerlist.append(player_id)
                    print self.BW_match_playerlist
                if self.bedwar_switch == True:
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] 游戏已经开始，请等待游戏结束后再匹配！\n§l§e您可选择进入观战区"}]}',
                                    player_id,
                                    False)

            if '点我加入' in text1:
                # 进入观战
                if self.bedwar_switch == False:
                    comp = serverApi.GetEngineCompFactory().CreateDimension(player_id)
                    comp.ChangePlayerDimension(0, (-91, 108, -147))
                    self.BW_aev_playerlist.append(player_id)
                if self.bedwar_switch == True:
                    self.BW_aev_playerlist.append(player_id)

                    comp = serverApi.GetEngineCompFactory().CreatePlayer(player_id)
                    suc = comp.SetPlayerRespawnPos((0, 80, 0), 2)
                    comp = serverApi.GetEngineCompFactory().CreateDimension(player_id)
                    comp.ChangePlayerDimension(2, (0, 80, 0))
                    comp = serverApi.GetEngineCompFactory().CreateFly(player_id)
                    comp.ChangePlayerFlyState(True)
                    # comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    # comp.SetCommand('/gamemode a', e, False)
                    comp = serverApi.GetEngineCompFactory().CreatePlayer(player_id)
                    comp.SetPlayerGameType(serverApi.GetMinecraftEnum().GameType.Adventure)

            if '点我获取' in text3:
                # 玩法攻略
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                comp.SetCommand(
                    '/tellraw @s {"rawtext": [{"text": "§l§e[功能介绍]\n §c1.穿戴或长按金胸甲加入匹配！\n§c2.右键或长按红石加入观战！\n§c3.游戏详细攻略请入群获取！"}]}',
                    player_id,
                    False)



    # 实体死亡
    def MobDieEvent(self, args):
        id = args['id']
        attacker = args['attacker']
        from mod_log import logger as logger
        comp = serverApi.GetEngineCompFactory().CreateEngineType(id)
        entityType = comp.GetEngineType()
        EntityTypeEnum = serverApi.GetMinecraftEnum().EntityType
        GetEngineTypeStr = comp.GetEngineTypeStr()
        print ("GetEngineTypeStr", comp.GetEngineTypeStr())
        if GetEngineTypeStr == "minecraft:ender_dragon":
            self.dr_switch = False
            if self.DC_check_teamname(attacker)[0] == "绿之队":
                for e in self.bedwar_teamslist_green_id:
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    comp.SetCommand("/give @s elytra 1", e, False)

            if self.DC_check_teamname(attacker)[0] == "蓝之队":
                for e in self.bedwar_teamslist_blue_id:
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    comp.SetCommand("/give @s elytra 1", e, False)

            if self.DC_check_teamname(attacker)[0] == "橙之队":
                for e in self.bedwar_teamslist_orange_id:
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    comp.SetCommand("/give @s elytra 1", e, False)

            if self.DC_check_teamname(attacker)[0] == "紫之队":
                for e in self.bedwar_teamslist_purple_id:
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    comp.SetCommand("/give @s elytra 1", e, False)

            team_kill = self.DC_check_teamname(attacker)
            team_kill_nickname = self.DC_check_nickname(attacker)
            comp.SetCommand("/title @a subtitle §c击败者：" + team_kill[1] + team_kill_nickname + '(' + \
                            team_kill[0] + ')', False)
            comp.SetCommand("/title @a title §5末影龙被击败！", False)
            context = '/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> ' + team_kill[1] + team_kill_nickname + '(' + \
                      team_kill[0] + ')' + " §c最后一击打败 §e末影龙 §c并获得 §5全队鞘翅" + '"}]}'
            comp.SetCommand(context, False)
            # context = '/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> §5龙息 §3可在商店兑换全队鞘翅，穿戴后1分钟有效！'  + '"}]}'
            # comp.SetCommand(context, False)

    # 当玩家即将破坏方块时，服务端线程触发该事件。
    def ServerPlayerTryDestroyBlockEvent(self, args):
        x = args['x']
        y = args['y']
        z = args['z']
        xyzs = (x, y, z)

        fullName = args['fullName']
        playerId = args['playerId']
        dimensionId = args['dimensionId']

        print "=== fullName"
        print fullName

        try:
            print "==== can_des.index"
            print self.can_des.index(fullName)
            args['cancel'] = False
            args['spawnResources'] = True
        except:
            # args['cancel'] = True
            args['spawnResources'] = False
            pass

        if fullName == "minecraft:bed":
            args['spawnResources'] = False
            if xyzs == (-75, 67, -129):  # 绿
                try:
                    self.bedwar_teamslist_green_id.index(playerId)
                    args['cancel'] = True
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    comp.SetCommand(
                        '/tellraw @s {"rawtext": [{"text": "§l§e起床战争>> §c你不能破坏自己队的床!"}]}', playerId, False)
                except:

                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())

                    comp.SetCommand(
                        '/title @a subtitle ' + "§c破坏者：" + self.DC_check_teamname(playerId)[1] + self.DC_check_nickname(
                            playerId) + "(" + self.DC_check_teamname(playerId)[0] + ")",
                        False)
                    comp.SetCommand('/title @a title §l§a绿之床被破坏！',
                                    False)
                    comp.SetCommand('/playsound mob.enderdragon.growl @a',
                                    False)
                    comp.SetCommand(
                        '/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> §a绿之床 §c被 ' + self.DC_check_teamname(playerId)[
                            1] + self.DC_check_nickname(playerId) + "(" + self.DC_check_teamname(playerId)[
                            0] + ")" + ' §c破坏!"}]}', playerId, False)

                    self.BW_bed_green = False

                    pass

            if xyzs == (109, 69, -125):  # 橙

                try:
                    self.bedwar_teamslist_orange_id.index(playerId)
                    args['cancel'] = True
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    comp.SetCommand(
                        '/tellraw @s {"rawtext": [{"text": "§l§e起床战争>> §c你不能破坏自己队的床!"}]}', playerId, False)
                except:

                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())

                    comp.SetCommand(
                        '/title @a subtitle ' + "§c破坏者：" + self.DC_check_teamname(playerId)[1] + self.DC_check_nickname(
                            playerId) + "(" + self.DC_check_teamname(playerId)[0] + ")",
                        False)
                    comp.SetCommand('/title @a title §l§6橙之床被破坏！',
                                    False)
                    comp.SetCommand('/playsound mob.enderdragon.growl @a',
                                    False)
                    comp.SetCommand(
                        '/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> §6橙之床 §c被 ' + self.DC_check_teamname(playerId)[
                            1] + self.DC_check_nickname(playerId) + "(" + self.DC_check_teamname(playerId)[
                            0] + ")" + ' §c破坏!"}]}', playerId, False)

                    self.BW_bed_orange = False

                    pass

            if xyzs == (104, 67, 129):  # 紫
                try:
                    self.bedwar_teamslist_purple_id.index(playerId)
                    args['cancel'] = True
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    comp.SetCommand(
                        '/tellraw @s {"rawtext": [{"text": "§l§e起床战争>> §c你不能破坏自己队的床!"}]}', playerId, False)
                except:
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())

                    comp.SetCommand(
                        '/title @a subtitle ' + "§c破坏者：" + self.DC_check_teamname(playerId)[1] + self.DC_check_nickname(
                            playerId) + "(" + self.DC_check_teamname(playerId)[0] + ")",
                        False)
                    comp.SetCommand('/title @a title §l§9紫之床被破坏！',
                                    False)
                    comp.SetCommand('/playsound mob.enderdragon.growl @a',
                                    False)
                    comp.SetCommand(
                        '/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> §9紫之床 §c被 ' + self.DC_check_teamname(playerId)[
                            1] + self.DC_check_nickname(playerId) + "(" + self.DC_check_teamname(playerId)[
                            0] + ")" + ' §c破坏!"}]}', playerId, False)

                    self.BW_bed_purple = False

                    pass

            if xyzs == (-85, 67, 126):  # 蓝
                try:
                    self.bedwar_teamslist_blue_id.index(playerId)
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    args['cancel'] = True
                    comp.SetCommand(
                        '/tellraw @s {"rawtext": [{"text": "§l§e起床战争>> §c你不能破坏自己队的床!"}]}', playerId, False)
                except:
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())

                    comp.SetCommand(
                        '/title @a subtitle ' + "§c破坏者：" + self.DC_check_teamname(playerId)[1] + self.DC_check_nickname(
                            playerId) + "(" + self.DC_check_teamname(playerId)[0] + ")",
                        False)
                    comp.SetCommand('/title @a title §l§3蓝之床被破坏！',
                                    False)
                    comp.SetCommand('/playsound mob.enderdragon.growl @a',
                                    False)
                    comp.SetCommand(
                        '/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> §3蓝之床 §c被 ' + self.DC_check_teamname(playerId)[
                            1] + self.DC_check_nickname(playerId) + "(" + self.DC_check_teamname(playerId)[
                            0] + ")" + ' §c破坏!"}]}', playerId, False)

                    self.BW_bed_blue = False

                    pass

    # Command命令执行成功事件
    def OnCommandOutputServerEvent(self, args):
        print args
        command = args['command']
        message = args['message']
        if command == "testfor":
            print "=== testfor"
            print message

    # 玩家点击右键尝试使用物品时服务端抛出的事件
    def ServerItemTryUseEvent(self, args):
        if args['itemDict']['newItemName'] == "minecraft:golden_chestplate":
            # 开始匹配
            if self.bedwar_switch == False:
                comp = serverApi.GetEngineCompFactory().CreateDimension(args['playerId'])
                comp.ChangePlayerDimension(0, (-91, 108, -124))
                self.BW_match_playerlist.append(args['playerId'])
                print self.BW_match_playerlist
                args['cancel'] = True

                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                com = "/replaceitem entity @s slot.armor.chest 0 minecraft:air"
                comp.SetCommand(com, args['playerId'], False)

            if self.bedwar_switch == True:
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] 游戏已经开始，请等待游戏结束后再匹配！您可选择红石进入观战区"}]}',
                                args['playerId'],
                                False)
                args['cancel'] = True

                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                com = "/replaceitem entity @s slot.armor.chest 0 minecraft:air"
                comp.SetCommand(com, args['playerId'], False)

        elif args['itemDict']['newItemName'] == "minecraft:redstone":
            # 进入观战
            if self.bedwar_switch == False:
                comp = serverApi.GetEngineCompFactory().CreateDimension(args['playerId'])
                comp.ChangePlayerDimension(0, (-91, 108, -147))
                self.BW_aev_playerlist.append(args['playerId'])
                args['cancel'] = True
            if self.bedwar_switch == True:
                comp = serverApi.GetEngineCompFactory().CreateDimension(args['playerId'])
                comp.ChangePlayerDimension(2, (0, 70, 0))
                self.BW_aev_playerlist.append(args['playerId'])
                comp = serverApi.GetEngineCompFactory().CreateFly(args['playerId'])
                comp.ChangePlayerFlyState(True)

                args['cancel'] = True

        elif args['itemDict']['newItemName'] == "minecraft:barrier":
            # 返回大厅
            if self.bedwar_switch == False:

                comp = serverApi.GetEngineCompFactory().CreateDimension(args['playerId'])
                comp.ChangePlayerDimension(0, (-112, 120, -138))
                try:
                    self.BW_match_playerlist.remove(args['playerId'])
                except:
                    pass
                try:
                    self.BW_aev_playerlist.remove(args['playerId'])
                except:
                    pass

                try:
                    self.bedwar_teamslist_green_id.remove(args['playerId'])
                except:
                    try:
                        self.bedwar_teamslist_orange_id.remove(args['playerId'])
                    except:
                        try:
                            self.bedwar_teamslist_blue_id.remove(args['playerId'])
                        except:
                            try:
                                self.bedwar_teamslist_purple_id.remove(args['playerId'])
                            except:
                                pass
                    pass

                args['cancel'] = True

                try:
                    self.bedwar_teamslist_green_id.remove(args['playerId'])
                except:
                    try:
                        self.bedwar_teamslist_orange_id.remove(args['playerId'])
                    except:
                        try:
                            self.bedwar_teamslist_blue_id.remove(args['playerId'])
                        except:
                            try:
                                self.bedwar_teamslist_purple_id.remove(args['playerId'])
                            except:
                                pass
                    pass

                comp = serverApi.GetEngineCompFactory().CreateName(args['playerId'])
                comp.SetPlayerPrefixAndSuffixName("", serverApi.GenerateColor('RED'), '',
                                                  serverApi.GenerateColor('RED'))

            if self.bedwar_switch == True:
                try:
                    self.BW_match_playerlist.remove(args['playerId'])
                except:
                    pass

                try:
                    self.BW_aev_playerlist.remove(args['playerId'])
                except:
                    pass

                try:
                    self.bedwar_teamslist_green_id.remove(args['playerId'])
                except:
                    try:
                        self.bedwar_teamslist_orange_id.remove(args['playerId'])
                    except:
                        try:
                            self.bedwar_teamslist_blue_id.remove(args['playerId'])
                        except:
                            try:
                                self.bedwar_teamslist_purple_id.remove(args['playerId'])
                            except:
                                pass
                    pass

                args['cancel'] = True

                comp = serverApi.GetEngineCompFactory().CreateName(args['playerId'])
                comp.SetPlayerPrefixAndSuffixName("", serverApi.GenerateColor('RED'), '',
                                                  serverApi.GenerateColor('RED'))

        elif args['itemDict']['newItemName'] == "minecraft:enchanted_book":
            # 玩法攻略
            comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            comp.SetCommand(
                '/tellraw @s {"rawtext": [{"text": "§l§e[功能介绍]\n §c1.穿戴或长按金胸甲加入匹配！\n§c2.右键或长按红石加入观战！\n§c3.游戏详细攻略请入群获取！"}]}',
                args['playerId'],
                False)

        elif args['itemDict']['newItemName'] == "kssae:purple_team_armor_main":
            # 紫队
            comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] §c自定义选队已暂停使用！"}]}', args['playerId'],
                            False)
            # args['cancel'] = True
            # if self.bedwar_switch == False:
            #     match_player_num = len(self.BW_match_playerlist)
            #     orange_num = len(self.bedwar_teamslist_orange_id)
            #     blue_num = len(self.bedwar_teamslist_blue_id)
            #     green_num = len(self.bedwar_teamslist_green_id)
            #     purple_num = len(self.bedwar_teamslist_purple_id)
            #     team_num = orange_num + blue_num + green_num + purple_num
            #
            #     try:
            #         self.bedwar_teamslist_purple_id.index(args['playerId'])
            #         print ("### purple_alr", True)
            #         comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #         comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] §9你已加入紫队！"}]}', args['playerId'],
            #                         False)
            #         comp.SetCommand('/clear @s', args['playerId'],
            #                         False)
            #
            #     except:
            #
            #         max_num = match_player_num / 2
            #
            #         if max_num <= 0:
            #             max_num = 1
            #
            #         if purple_num >= max_num:
            #             comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #             comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] §9紫队已满，请加入其他队伍！"}]}',
            #                             args['playerId'],
            #                             False)
            #             comp.SetCommand('/clear @s', args['playerId'],
            #                             False)
            #
            #             if self.DC_check_teamname(args['playerId'])[0] == "":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 air"
            #                 comp.SetCommand(com, args['playerId'], False)
            #             elif self.DC_check_teamname(args['playerId'])[0] == "绿之队":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 kssae:green_team_armor_main"
            #                 comp.SetCommand(com, args['playerId'], False)
            #             elif self.DC_check_teamname(args['playerId'])[0] == "蓝之队":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 kssae:blue_team_armor_main"
            #                 comp.SetCommand(com, args['playerId'], False)
            #             elif self.DC_check_teamname(args['playerId'])[0] == "橙之队":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 kssae:orange_team_armor_main"
            #                 comp.SetCommand(com, args['playerId'], False)
            #             elif self.DC_check_teamname(args['playerId'])[0] == "紫之队":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 kssae:purple_team_armor_main"
            #                 comp.SetCommand(com, args['playerId'], False)
            #         else:
            #             comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #             comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] §9加入紫队成功！"}]}', args['playerId'],
            #                             False)
            #             try:
            #                 self.bedwar_teamslist_green_id.remove(args['playerId'])
            #             except:
            #                 try:
            #                     self.bedwar_teamslist_orange_id.remove(args['playerId'])
            #                 except:
            #                     try:
            #                         self.bedwar_teamslist_blue_id.remove(args['playerId'])
            #                     except:
            #                         try:
            #                             self.bedwar_teamslist_purple_id.remove(args['playerId'])
            #                         except:
            #                             pass
            #                 pass
            #
            #             self.bedwar_teamslist_purple_id.append(args['playerId'])
            #             comp = serverApi.GetEngineCompFactory().CreateName(args['playerId'])
            #             comp.SetPlayerPrefixAndSuffixName("", serverApi.GenerateColor('RED'), ' <紫之队>',
            #                                               serverApi.GenerateColor('DARK_PURPLE'))
            #
            #         pass

        elif args['itemDict']['newItemName'] == "kssae:blue_team_armor_main":
            # 蓝队
            args['cancel'] = True
            comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] §c自定义选队已暂停使用！"}]}', args['playerId'],
                            False)
            # if self.bedwar_switch == False:
            #     match_player_num = len(self.BW_match_playerlist)
            #     orange_num = len(self.bedwar_teamslist_orange_id)
            #     blue_num = len(self.bedwar_teamslist_blue_id)
            #     green_num = len(self.bedwar_teamslist_green_id)
            #     purple_num = len(self.bedwar_teamslist_purple_id)
            #     team_num = orange_num + blue_num + green_num + purple_num
            #     print ("### blue_try", True)
            #     print ("### arr", blue_num)
            #     try:
            #         self.bedwar_teamslist_blue_id.index(args['playerId'])
            #         print ("### blue_alr", True)
            #         comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #         comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] §3你已加入蓝队！"}]}', args['playerId'],
            #                         False)
            #         comp.SetCommand('/clear @s', args['playerId'],
            #                         False)
            #     except:
            #         print ("### blue_except", True)
            #         max_num = match_player_num / 2
            #
            #         if max_num <= 0:
            #             max_num = 1
            #
            #         if blue_num >= max_num:
            #             comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #             comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] §3蓝队已满，请加入其他队伍！"}]}',
            #                             args['playerId'],
            #                             False)
            #             comp.SetCommand('/clear @s', args['playerId'],
            #                             False)
            #
            #             if self.DC_check_teamname(args['playerId'])[0] == "":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 air"
            #                 comp.SetCommand(com, args['playerId'], False)
            #             elif self.DC_check_teamname(args['playerId'])[0] == "绿之队":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 kssae:green_team_armor_main"
            #                 comp.SetCommand(com, args['playerId'], False)
            #             elif self.DC_check_teamname(args['playerId'])[0] == "蓝之队":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 kssae:blue_team_armor_main"
            #                 comp.SetCommand(com, args['playerId'], False)
            #             elif self.DC_check_teamname(args['playerId'])[0] == "橙之队":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 kssae:orange_team_armor_main"
            #                 comp.SetCommand(com, args['playerId'], False)
            #             elif self.DC_check_teamname(args['playerId'])[0] == "紫之队":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 kssae:purple_team_armor_main"
            #                 comp.SetCommand(com, args['playerId'], False)
            #
            #         else:
            #             comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #             comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] §3加入蓝队成功！"}]}', args['playerId'],
            #                             False)
            #             try:
            #                 self.bedwar_teamslist_green_id.remove(args['playerId'])
            #             except:
            #                 try:
            #                     self.bedwar_teamslist_orange_id.remove(args['playerId'])
            #                 except:
            #                     try:
            #                         self.bedwar_teamslist_blue_id.remove(args['playerId'])
            #                     except:
            #                         try:
            #                             self.bedwar_teamslist_purple_id.remove(args['playerId'])
            #                         except:
            #                             pass
            #                 pass
            #             self.bedwar_teamslist_blue_id.append(args['playerId'])
            #             comp = serverApi.GetEngineCompFactory().CreateName(args['playerId'])
            #             comp.SetPlayerPrefixAndSuffixName("", serverApi.GenerateColor('RED'), ' <蓝之队>',
            #                                               serverApi.GenerateColor('AQUA'))
            #         pass

        elif args['itemDict']['newItemName'] == "kssae:green_team_armor_main":
            # 绿队
            args['cancel'] = True
            comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] §c自定义选队已暂停使用！"}]}', args['playerId'],
                            False)
            # if self.bedwar_switch == False:
            #     match_player_num = len(self.BW_match_playerlist)
            #     orange_num = len(self.bedwar_teamslist_orange_id)
            #     blue_num = len(self.bedwar_teamslist_blue_id)
            #     green_num = len(self.bedwar_teamslist_green_id)
            #     purple_num = len(self.bedwar_teamslist_purple_id)
            #     team_num = orange_num + blue_num + green_num + purple_num
            #
            #     try:
            #         self.bedwar_teamslist_green_id.index(args['playerId'])
            #         print ("### green_alr", True)
            #         comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #         comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] §a您已加入绿队！"}]}', args['playerId'],
            #                         False)
            #         comp.SetCommand('/clear @s', args['playerId'],
            #                         False)
            #
            #     except:
            #
            #         max_num = match_player_num / 2
            #
            #         if max_num <= 0:
            #             max_num = 1
            #
            #         if green_num >= max_num:
            #             comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #             comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] §a绿队已满，请加入其他队伍！"}]}',
            #                             args['playerId'],
            #                             False)
            #             comp.SetCommand('/clear @s', args['playerId'],
            #                             False)
            #
            #             if self.DC_check_teamname(args['playerId'])[0] == "":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 air"
            #                 comp.SetCommand(com, args['playerId'], False)
            #             elif self.DC_check_teamname(args['playerId'])[0] == "绿之队":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 kssae:green_team_armor_main"
            #                 comp.SetCommand(com, args['playerId'], False)
            #             elif self.DC_check_teamname(args['playerId'])[0] == "蓝之队":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 kssae:blue_team_armor_main"
            #                 comp.SetCommand(com, args['playerId'], False)
            #             elif self.DC_check_teamname(args['playerId'])[0] == "橙之队":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 kssae:orange_team_armor_main"
            #                 comp.SetCommand(com, args['playerId'], False)
            #             elif self.DC_check_teamname(args['playerId'])[0] == "紫之队":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 kssae:purple_team_armor_main"
            #                 comp.SetCommand(com, args['playerId'], False)
            #         else:
            #             comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #             comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] §a加入绿队成功！"}]}', args['playerId'],
            #                             False)
            #             try:
            #                 self.bedwar_teamslist_green_id.remove(args['playerId'])
            #             except:
            #                 try:
            #                     self.bedwar_teamslist_orange_id.remove(args['playerId'])
            #                 except:
            #                     try:
            #                         self.bedwar_teamslist_blue_id.remove(args['playerId'])
            #                     except:
            #                         try:
            #                             self.bedwar_teamslist_purple_id.remove(args['playerId'])
            #                         except:
            #                             pass
            #                 pass
            #             self.bedwar_teamslist_green_id.append(args['playerId'])
            #             comp = serverApi.GetEngineCompFactory().CreateName(args['playerId'])
            #             comp.SetPlayerPrefixAndSuffixName("", serverApi.GenerateColor('RED'), ' <绿之队>',
            #                                               serverApi.GenerateColor('GREEN'))
            #         pass

        elif args['itemDict']['newItemName'] == "kssae:orange_team_armor_main":
            # 橙队
            args['cancel'] = True
            comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] §c自定义选队已暂停使用！"}]}', args['playerId'],
                            False)
            # if self.bedwar_switch == False:
            #
            #     match_player_num = len(self.BW_match_playerlist)
            #     orange_num = len(self.bedwar_teamslist_orange_id)
            #     blue_num = len(self.bedwar_teamslist_blue_id)
            #     green_num = len(self.bedwar_teamslist_green_id)
            #     purple_num = len(self.bedwar_teamslist_purple_id)
            #     team_num = orange_num + blue_num + green_num + purple_num
            #
            #     try:
            #         self.bedwar_teamslist_orange_id.index(args['playerId'])
            #         print ("### orange_alr", True)
            #         comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #         comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] §6您已加入橙队！"}]}', args['playerId'],
            #                         False)
            #         comp.SetCommand('/clear @s', args['playerId'],
            #                         False)
            #
            #     except:
            #         max_num = match_player_num / 2
            #
            #         if max_num <= 0:
            #             max_num = 1
            #
            #         if orange_num >= max_num:
            #             comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #             comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] §6橙队已满，请加入其他队伍！"}]}',
            #                             args['playerId'],
            #                             False)
            #             comp.SetCommand('/clear @s', args['playerId'],
            #                             False)
            #
            #             if self.DC_check_teamname(args['playerId'])[0] == "":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 air"
            #                 comp.SetCommand(com, args['playerId'], False)
            #             elif self.DC_check_teamname(args['playerId'])[0] == "绿之队":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 kssae:green_team_armor_main"
            #                 comp.SetCommand(com, args['playerId'], False)
            #             elif self.DC_check_teamname(args['playerId'])[0] == "蓝之队":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 kssae:blue_team_armor_main"
            #                 comp.SetCommand(com, args['playerId'], False)
            #             elif self.DC_check_teamname(args['playerId'])[0] == "橙之队":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 kssae:orange_team_armor_main"
            #                 comp.SetCommand(com, args['playerId'], False)
            #             elif self.DC_check_teamname(args['playerId'])[0] == "紫之队":
            #                 comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #                 com = "/replaceitem entity @s slot.armor.chest 0 kssae:purple_team_armor_main"
            #                 comp.SetCommand(com, args['playerId'], False)
            #         else:
            #             comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #             comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] §6加入橙队成功！"}]}', args['playerId'],
            #                             False)
            #             try:
            #                 self.bedwar_teamslist_green_id.remove(args['playerId'])
            #             except:
            #                 try:
            #                     self.bedwar_teamslist_orange_id.remove(args['playerId'])
            #                 except:
            #                     try:
            #                         self.bedwar_teamslist_blue_id.remove(args['playerId'])
            #                     except:
            #                         try:
            #                             self.bedwar_teamslist_purple_id.remove(args['playerId'])
            #                         except:
            #                             pass
            #                 pass
            #             self.bedwar_teamslist_orange_id.append(args['playerId'])
            #             comp = serverApi.GetEngineCompFactory().CreateName(args['playerId'])
            #             comp.SetPlayerPrefixAndSuffixName("", serverApi.GenerateColor('RED'), ' <橙之队>',
            #                                               serverApi.GenerateColor('MINECOIN_GOLD'))
            #
            #         pass

        if args['itemDict']['newItemName'] == "kssae:item_2":
            print ("###item_2")
            comp = serverApi.GetEngineCompFactory().CreateItem(args['playerId'])
            slotId = comp.GetSelectSlotId()
            comp = serverApi.GetEngineCompFactory().CreateItem(args['playerId'])
            comp.AddEnchantToInvItem(slotId, serverApi.GetMinecraftEnum().EnchantType.WeaponKnockback, 5)

    # 玩家退出游戏
    def PlayerLeftMessageServerEvent(self, args):
        print "PlayerLeftMessageServerEvent"
        info = {"id":args['id'],"name":args['name']}
        self.playerlist.remove(info)
        try:
            self.bedwar_teamslist_green_id.remove(args['id'])
        except:
            try:
                self.bedwar_teamslist_blue_id.remove(args['id'])
            except:
                try:
                    self.bedwar_teamslist_orange_id.remove(args['id'])
                except:
                    try:
                        self.bedwar_teamslist_purple_id.remove(args['id'])
                    except:
                        pass

        try:
            self.BW_aev_playerlist.remove(args['id'])
        except:
            pass

    # 玩家维度改变时服务端抛出
    def DimensionChangeServerEvent(self, args):
        print "===== 【检测到正在维度传送】 ====="
        # comp = serverApi.GetEngineCompFactory().CreateDimension(args['playerId'])
        # if self.DC_check_teamname(args['playerId'])[0] == "紫之队":
        #     comp.ChangePlayerDimension(2, (91, 69, 140))
        # if self.DC_check_teamname(args['playerId'])[0] == "绿之队":
        #     comp.ChangePlayerDimension(2, (-62, 69, -139))
        # if self.DC_check_teamname(args['playerId'])[0] == "蓝之队":
        #     comp.ChangePlayerDimension(2, (-98, 69, 137))
        # if self.DC_check_teamname(args['playerId'])[0] == "橙之队":
        #     comp.ChangePlayerDimension(2, (96, 71, -136))

    # 触发时机：当玩家死亡时触发该事件。
    def PlayerDieEvent(self, args):
        print "===== 【检测到玩家已死亡】 ====="
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        print (self.playerlist)
        print (args)
        self.BW_aev_playerlist.append(args['id'])

        team_die = self.DC_check_teamname(args['id'])
        team_die_nickname = self.DC_check_nickname(args['id'])
        team_kill = self.DC_check_teamname(args['attacker'])
        team_kill_nickname = self.DC_check_nickname(args['attacker'])

        comp = serverApi.GetEngineCompFactory().CreatePlayer(args['id'])
        comp.SetPlayerGameType(serverApi.GetMinecraftEnum().GameType.Adventure)

        # 给予玩家飞行模式
        comp = serverApi.GetEngineCompFactory().CreateFly(args['id'])
        comp.ChangePlayerFlyState(True)
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())

        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        if team_kill[0] == "系统":
            context = '/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> ' + team_die[1] + team_die_nickname + '(' + \
                      team_die[
                          0] + ')' + ' 不知为何就寄了"}]}'
            comp.SetCommand(context, args['id'], False)
        else:
            context = '/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> ' + team_kill[1] + team_kill_nickname + '(' + \
                      team_kill[0] + ')' + " §4杀死了 " + team_die[1] + team_die_nickname + '(' + team_die[
                          0] + ')' + '"}]}'
            comp.SetCommand(context, args['id'], False)

        comp = serverApi.GetEngineCompFactory().CreateDimension(args['id'])
        print "==== 断点记录1 ===="
        print self.DC_check_teamname(args['id'])
        if self.DC_check_teamname(args['id'])[0] == "紫之队":
            comp.ChangePlayerDimension(2, (91, 72, 140))
        if self.DC_check_teamname(args['id'])[0] == "绿之队":
            comp.ChangePlayerDimension(2, (-62, 72, -139))
        if self.DC_check_teamname(args['id'])[0] == "蓝之队":
            comp.ChangePlayerDimension(2, (-98, 72, 137))
        if self.DC_check_teamname(args['id'])[0] == "橙之队":
            comp.ChangePlayerDimension(2, (96, 75, -136))
        print "==== 断点记录2 ===="
        team = self.DC_check_teamname(args['id'])[0]
        team_color = self.DC_check_teamname(args['id'])[1]
        print "=== 复活team：" + team
        d = False
        if team == "绿之队":
            if self.BW_bed_green == True:
                d = True
        if team == "蓝之队":
            if self.BW_bed_blue == True:
                d = True
        if team == "橙之队":
            print "=== 复活self.BW_bed_orange：" + str(self.BW_bed_orange)
            if self.BW_bed_orange == True:
                d = True
        if team == "紫之队":
            if self.BW_bed_purple == True:
                d = True
        print "=== 复活d：" + str(d)
        if d == True:
            self.dead_list.append(
                [args['id'], self.DC_check_nickname(args['id']), self.DC_check_teamname(args['id'])[0], 10])

            # comp.SetCommand('/gamemode a @s', args['id'], False)

            comp = serverApi.GetEngineCompFactory().CreatePlayer(args['id'])
            comp.SetPlayerGameType(serverApi.GetMinecraftEnum().GameType.Adventure)

            comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            comp.SetCommand("/title @s title §l§e10§l§2秒后复活", args['id'], False)
        else:
            self.hide_id = args['id']
            self.TIME_LATER_FUN("hide_c", 1)
            self.BW_aev_playerlist.append(args['id'])

        green_num_in = len(self.bedwar_teamslist_green_id)
        blue_num_in = len(self.bedwar_teamslist_blue_id)
        orange_num_in = len(self.bedwar_teamslist_orange_id)
        purple_num_in = len(self.bedwar_teamslist_purple_id)

        if d == False:
            if team == "绿之队":
                self.bedwar_teamslist_green_id.remove(args['id'])
            if team == "蓝之队":
                self.bedwar_teamslist_blue_id.remove(args['id'])
            if team == "橙之队":
                self.bedwar_teamslist_orange_id.remove(args['id'])
            if team == "紫之队":
                self.bedwar_teamslist_purple_id.remove(args['id'])

        green_num = len(self.bedwar_teamslist_green_id)
        blue_num = len(self.bedwar_teamslist_blue_id)
        orange_num = len(self.bedwar_teamslist_orange_id)
        purple_num = len(self.bedwar_teamslist_purple_id)

        if green_num == 0 and green_num_in - green_num >= 1:
            # 被消灭
            comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            comp.SetCommand('/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> ' + team_color +
                            team + '§c 被消灭！"}]}', False)

            comp.SetCommand('/effect @s invisibility 9999 255 true', args['id'], False)
            comp.SetCommand('/effect @s instant_health 9999 255 true', args['id'], False)
            comp.SetCommand('/effect @s weakness 99999 255 true', args['id'], False)
            comp.SetCommand('/effect @s instant_health 99999 255 true', args['id'], False)

            comp.SetCommand('/clear @s', args['id'], False)
        if blue_num == 0 and blue_num_in - blue_num >= 1:
            # 被消灭
            comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            comp.SetCommand('/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> ' + team_color +
                            team + '§c 被消灭！"}]}', False)

            comp.SetCommand('/effect @s invisibility 9999 255 true', args['id'], False)
            comp.SetCommand('/effect @s instant_health 9999 255 true', args['id'], False)
            comp.SetCommand('/effect @s weakness 99999 255 true', args['id'], False)
            comp.SetCommand('/effect @s instant_health 99999 255 true', args['id'], False)

            comp.SetCommand('/clear @s', args['id'], False)
        if orange_num == 0 and orange_num_in - orange_num >= 1:
            # 被消灭
            comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            comp.SetCommand('/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> ' + team_color +
                            team + '§c 被消灭！"}]}', False)

            comp.SetCommand('/effect @s invisibility 9999 255 true', args['id'], False)
            comp.SetCommand('/effect @s instant_health 9999 255 true', args['id'], False)
            comp.SetCommand('/effect @s weakness 99999 255 true', args['id'], False)
            comp.SetCommand('/effect @s instant_health 99999 255 true', args['id'], False)

            comp.SetCommand('/clear @s', args['id'], False)
        if purple_num == 0 and purple_num_in - purple_num >= 1:
            # 被消灭
            comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            comp.SetCommand('/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> ' + team_color +
                            team + '§c 被消灭！"}]}', False)

            comp.SetCommand('/effect @s invisibility 9999 255 true', args['id'], False)
            comp.SetCommand('/effect @s instant_health 9999 255 true', args['id'], False)
            comp.SetCommand('/effect @s weakness 99999 255 true', args['id'], False)
            comp.SetCommand('/effect @s instant_health 99999 255 true', args['id'], False)
            comp.SetCommand('/clear @s', args['id'], False)

    # 玩家尝试使用床睡觉
    def PlayerTrySleepServerEvent(self, args):
        print "===== 【检测到玩家睡觉】 ====="
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e[系统] §4不允许玩家睡觉"}]}', args['playerId'], False)
        args['cancel'] = True
        print (self.playerlist)

    # 触发时机：准备显示“xxx加入游戏”的玩家登录提示文字时服务端抛出的事件。
    def OnPlayerJoinMessageEvent(self, args):

        print "===== 【称号系统：2023年1月16日16点41分更新修复】 ====="
        print args
        playerid = args['id']
        nickname = args['name']
        info = {'id':playerid,'name':nickname}
        comp = serverApi.GetEngineCompFactory().CreatePlayer(playerid)
        self.map_entityId[playerid] = nickname
        self.all_entityId.append(playerid)
        print self.map_entityId
        print 'playerid' + " ==> " + playerid
        print 'nickname' + " ==> " + nickname
        comp = serverApi.GetEngineCompFactory().CreateHttp(serverApi.GetLevelId())
        uid = comp.GetPlayerUid(playerid)
        print ("###args ====",type(args))
        self.playerlist.append(info)

        comp = serverApi.GetEngineCompFactory().CreatePlayer(playerid)
        comp.SetPlayerGameType(serverApi.GetMinecraftEnum().GameType.Adventure)

        if self.bedwar_switch == True:
            self.playerlist_new.append(args)
            comp = serverApi.GetEngineCompFactory().CreateDimension(args['id'])
            comp.ChangePlayerDimension(0, (-112, 120, -138))

        if self.bedwar_switch == False:
            comp = serverApi.GetEngineCompFactory().CreateDimension(args['id'])
            comp.ChangePlayerDimension(0, (-112, 120, -138))

            # playerId = args['id']
            # itemDict = {
            #     'itemName': 'minecraft:golden_chestplate',
            #     'count': 1,
            #     'enchantData': [(serverApi.GetMinecraftEnum().EnchantType.BowDamage, 1), ],
            #     'auxValue': 0,
            #     'customTips': '§e 开始匹配 §r',
            #     'extraId': 'abc',
            #     'userData': {},
            # }
            # comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
            # comp.SpawnItemToPlayerInv(itemDict, playerId, 2)
            #
            # itemDict = {
            #     'itemName': 'minecraft:redstone',
            #     'count': 1,
            #     'enchantData': [(serverApi.GetMinecraftEnum().EnchantType.BowDamage, 1), ],
            #     'auxValue': 0,
            #     'customTips': '§9 观战 §r',
            #     'extraId': 'abc',
            #     'userData': {},
            # }
            # comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
            # comp.SpawnItemToPlayerInv(itemDict, playerId, 7)

        # if nickname == "初云如梦" or nickname == "我是初云" or nickname == "我是初云工作室":
        #     comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        #     comp.SetCommand("/title @a title §l§9" + nickname, playerid, False)
        #     comp.SetCommand("/title @a subtitle §l§6地图作者加入了游戏", playerid, False)
        #     self.commands_player_list.append(playerid)
        #     print self.commands_player_list
        #     comp = serverApi.GetEngineCompFactory().CreateName(playerid)
        #     comp.SetPlayerPrefixAndSuffixName("<地图作者>", serverApi.GenerateColor('YELLOW'), '',
        #                                       serverApi.GenerateColor('RED'))
        # else:
        #     print "===== 检查是否为地图管理员 ====="
        #     li = ['我是初云工作室', '我是小初云']
        #     key = nickname
        #     i = len(li) - 1
        #     print "==== " + str(i)
        #     print "==== " + key
        #     while i >= 0:
        #         print li[i]
        #         if li[i] == key:
        #             print key + ' 是管理员'
        #             comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        #             comp.SetCommand("/title @a title §l§9" + nickname, playerid, False)
        #             comp.SetCommand("/title @a subtitle §l§2地图管理员加入了游戏", playerid, False)
        #             self.commands_player_list.append(playerid)
        #             print self.commands_player_list
        #             comp = serverApi.GetEngineCompFactory().CreateName(playerid)
        #             comp.SetPlayerPrefixAndSuffixName("<地图管理员>", serverApi.GenerateColor('BLUE'), '',
        #                                               serverApi.GenerateColor('RED'))
        #             break
        #         else:
        #             i -= 1
        #
        #     print "===== 检查是否为地图巡查员 ====="
        #     li = self.title_green
        #     key = nickname
        #     i = len(li) - 1
        #     print "==== " + str(i)
        #     while i >= 0:
        #         print li[i]
        #         if li[i] == key:
        #             print key + ' 是巡查员'
        #             comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        #             comp.SetCommand("/title @a title §l§9" + nickname, playerid, False)
        #             comp.SetCommand("/title @a subtitle §l§a地图巡查员加入了游戏", playerid, False)
        #             comp = serverApi.GetEngineCompFactory().CreateName(playerid)
        #             comp.SetPlayerPrefixAndSuffixName("<地图巡查员>", serverApi.GenerateColor('GREEN'), '',
        #                                               serverApi.GenerateColor('RED'))
        #             break
        #         else:
        #             i -= 1
        #
        #     print "===== 检查是否有纪念称号 ====="
        #     li = self.title_red
        #     key = nickname
        #     i = len(li) - 1
        #     print "==== " + str(i)
        #     while i >= 0:
        #         print li[i]
        #         if li[i] == key:
        #             print key + ' 有纪念称号'
        #             comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        #             comp.SetCommand("/title @a title §l§9" + nickname, playerid, False)
        #             comp.SetCommand("/title @a subtitle §l§4元老玩家加入了游戏", playerid, False)
        #             comp = serverApi.GetEngineCompFactory().CreateName(playerid)
        #             comp.SetPlayerPrefixAndSuffixName("<元老玩家>", serverApi.GenerateColor('RED'), '',
        #                                               serverApi.GenerateColor('RED'))
        #             break
        #         else:
        #             i -= 1
        #
        #     print "===== 检查是否是黑名单 ====="
        #     li = self.title_black
        #     key = nickname
        #     i = len(li) - 1
        #     print "==== " + str(i)
        #     while i >= 0:
        #         print li[i]
        #         if li[i] == key:
        #             print key + ' 是黑名单'
        #             comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        #             comp.SetCommand("/title @a title §l§9" + nickname, playerid, False)
        #             comp.SetCommand("/title @a subtitle §l§0黑名单加入了游戏", playerid, False)
        #             comp.SetCommand(
        #                 "/say \n系统提醒：\n§l§c" + nickname + " 是黑名单玩家，会破坏游戏体验，请房主立即踢出！\n§l§6【欢迎入群举报！】" + "\n踢出指令：§l§c/kick " + nickname,
        #                 playerid, False)
        #             comp.SetCommand("/kick " + nickname + " \n你已被纳入黑名单，如有问题请入群申诉！\n企鹅\n群\n881304734", playerid, False)
        #             comp = serverApi.GetEngineCompFactory().CreateName(playerid)
        #             comp.SetPlayerPrefixAndSuffixName("<黑名单玩家>", serverApi.GenerateColor('BLACK'), '<请房主立即踢出>',
        #                                               serverApi.GenerateColor('RED'))
        #             break
        #         else:
        #             i -= 1
        #
        #     print "===== 检查是否有颁发称号 ====="
        #     li = self.title_purple
        #     key = nickname
        #     i = len(li) - 1
        #     print "==== " + str(i)
        #     if len(li[key]) > 0:
        #         print key + ' 有颁发称号'
        #         comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        #         comp.SetCommand("/title @a title §l§9" + nickname, playerid, False)
        #         comp.SetCommand("/title @a subtitle §l§5" + li[key] + "加入了游戏", playerid, False)
        #         comp = serverApi.GetEngineCompFactory().CreateName(playerid)
        #         comp.SetPlayerPrefixAndSuffixName("<" + li[key] + ">", serverApi.GenerateColor('DARK_PURPLE'), '',
        #                                           serverApi.GenerateColor('RED'))

    # 监听观战玩家攻击事件
    def OnPlayerAttackEntityEvent(self, args):
        print "==== 玩家攻击 ===="
        print args
        print ("观战玩家列表", self.BW_aev_playerlist)
        for item in self.BW_aev_playerlist:
            print item
            if item == args['playerId']:
                print "取消"
                args['cancel'] = True
                break

        playerId = args['playerId']
        victimId = args['victimId']

        team = self.DC_check_teamname(playerId)[0]

        if team == "蓝之队":
            for e in self.bedwar_teamslist_blue_id:
                if victimId == e:
                    args['cancel'] = True

        if team == "绿之队":
            for e in self.bedwar_teamslist_green_id:
                if victimId == e:
                    args['cancel'] = True

        if team == "橙之队":
            for e in self.bedwar_teamslist_orange_id:
                if victimId == e:
                    args['cancel'] = True

        if team == "紫之队":
            for e in self.bedwar_teamslist_purple_id:
                if victimId == e:
                    args['cancel'] = True

    # 玩家发送聊天信息时触发
    def OnServerChat(self, args):
        print "==== OnServerChat ==== ", args
        playerId = args["playerId"]

        for i in self.bedwar_teamslist_orange_id:
            if playerId == i:
                args['gameChatPrefix'] = "§6[橙队]§0"

        for i in self.bedwar_teamslist_blue_id:
            if playerId == i:
                args['gameChatPrefix'] = "§3[蓝队]§0"

        for i in self.bedwar_teamslist_purple_id:
            if playerId == i:
                args['gameChatPrefix'] = "§9[紫队]§0"

        for i in self.bedwar_teamslist_green_id:
            if playerId == i:
                args['gameChatPrefix'] = "§a[绿队]§0"

        comp = compFactory.CreateItem(playerId)
        if args["message"] == "开启观战模式":
            key = self.map_entityId[playerId]
            # li = self.title_yellow
            # i = len(self.title_yellow)
            # print i
            # while i >= 0:
            #     print li
            #     if li[i - 1] == key:
            #         print key + ' 是地图管理层'
            #         comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #         comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§3已开启观战模式"}]}', playerId, False)
            #         li = self.guanzhanPlayer
            #         key = playerId
            #         i = len(li)
            #         print "==== " + str(i)
            #         print "==== " + key
            #         if i == 0:
            #             self.guanzhanPlayer.append(playerId)
            #         else:
            #             while i > 0:
            #                 i -= 1
            #                 print li[i]
            #                 if li[i] == key:
            #                     break
            #                 elif i == 0:
            #                     self.guanzhanPlayer.append(playerId)
            #
            #         # 给予玩家飞行模式
            #         comp = serverApi.GetEngineCompFactory().CreateFly(playerId)
            #         comp.ChangePlayerFlyState(True)
            #         comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #
            #         comp.SetCommand('/effect @s invisibility 9999 255 true', playerId, False)
            #         comp.SetCommand('/effect @s instant_health 9999 255 true', playerId, False)
            #         comp.SetCommand('/effect @s weakness 99999 255 true', playerId, False)
            #         comp.SetCommand('/effect @s instant_health 99999 255 true', playerId, False)
            #
            #         comp.SetCommand('/clear @s', playerId, False)
            #         print "==== 观战玩家列表 ===="
            #         print self.guanzhanPlayer
            #
            #         break
            #     else:
            #         i -= 1
            #         if i == 0:
            #             print key + ' 不是地图管理层'
            #             comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #             comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§3为了保证游戏平衡，仅OP可用观战模式"}]}', playerId,
            #                             False)

        # elif args["message"] == "关闭观战模式":
        # key = self.map_entityId[playerId]
        # li = self.title_yellow
        # i = len(self.title_yellow)
        # while i >= 0:
        #     print li
        #     if li[i - 1] == key:
        #         print key + ' 是地图管理层'
        #         comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        #         comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§5已关闭观战模式"}]}', playerId, False)
        #         li = self.guanzhanPlayer
        #         key = playerId
        #         i = len(li)
        #         print "==== " + str(i)
        #         print "==== " + key
        #         if i != 0:
        #             while i > 0:
        #                 i -= 1
        #                 if li[i] == key:
        #                     for item in self.guanzhanPlayer:
        #                         print item
        #                         if item == playerId:
        #                             self.guanzhanPlayer.remove(item)
        #                             break
        #
        #         # 关闭玩家飞行模式
        #         comp = serverApi.GetEngineCompFactory().CreateFly(playerId)
        #         comp.ChangePlayerFlyState(False)
        #         comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        #         # comp.SetCommand('/effect @s clear', playerId, False)
        #         print "==== 观战玩家列表 ===="
        #         print self.guanzhanPlayer
        #     else:
        #         i -= 1
        #         if i == 0:
        #             print key + ' 不是地图管理层'
        #             comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        #             comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§3为了保证游戏平衡，仅OP可用观战模式"}]}', playerId,
        #                             False)

        elif args["message"] == "模拟重复队伍":
            self.bedwar_teamslist_purple_id.append('-1')
            self.bedwar_teamslist_orange_id.append('-1')
            self.bedwar_teamslist_green_id.append('-1')

        elif args["message"] == "关闭命令方块":
            key = self.map_entityId[playerId]
            li = self.title_yellow
            i = len(self.title_yellow)
            while i >= 0:
                print li
                if li[i - 1] == key:
                    print key + ' 是地图管理层'
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§5命令方块已关闭（保活失效）"}]}', playerId, False)
                    self.com_safe_switch = False
                    li = self.guanzhanPlayer
                    key = playerId
                    i = len(li)
                    print "==== " + str(i)
                    print "==== " + key
                    if i != 0:
                        while i > 0:
                            i -= 1
                            if li[i] == key:
                                for item in self.guanzhanPlayer:
                                    print item
                                    if item == playerId:
                                        self.guanzhanPlayer.remove(item)
                                        break

                    # 关闭命令方块
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    comp.SetCommand('/gamerule commandblocksenabled false', playerId, False)
                else:
                    i -= 1
                    if i == 0:
                        print key + ' 不是地图管理层'
                        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                        comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§3仅超管可关闭命令方块！"}]}', playerId,
                                        False)

        elif args["message"] == "开启命令方块":
            key = self.map_entityId[playerId]
            li = self.title_yellow
            i = len(self.title_yellow)
            while i >= 0:
                print li
                if li[i - 1] == key:
                    print key + ' 是地图管理层'
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§5命令方块已开启（保活启动）"}]}', playerId, False)
                    self.com_safe_switch = True
                    li = self.guanzhanPlayer
                    key = playerId
                    i = len(li)
                    print "==== " + str(i)
                    print "==== " + key
                    if i != 0:
                        while i > 0:
                            i -= 1
                            if li[i] == key:
                                for item in self.guanzhanPlayer:
                                    print item
                                    if item == playerId:
                                        self.guanzhanPlayer.remove(item)
                                        break

                    # 开启命令方块
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    comp.SetCommand('/gamerule commandblocksenabled true', playerId, False)
                else:
                    i -= 1
                    if i == 0:
                        print key + ' 不是地图管理层'
                        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                        comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§3仅超管可关闭命令方块！"}]}', playerId,
                                        False)

        # elif args["message"] == "测试刷新资源":
        #     comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        #     self.create_sw = False
        #     if self.bedwar_switch == False:
        #         comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§3开始刷新资源"}]}', playerId,
        #                         False)
        #         self.bedwar_switch = True
        #     elif self.bedwar_switch == True:
        #         comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§3已停止刷新资源"}]}', playerId,
        #                         False)
        #         self.bedwar_switch = False
        #
        # elif args["message"] == "开始游戏":
        #     self.BW_game_start()
        #
        # elif args["message"] == "效果测试":
        #     print "============ effect ==="
        #     comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        #     comp.SetCommand('/effect @s invisibility 9999 255 true', playerId, False)
        #     comp.SetCommand('/effect @s instant_health 9999 255 true', playerId, False)
        #     comp.SetCommand('/effect @s weakness 99999 255 true', playerId, False)
        #     comp.SetCommand('/effect @s instant_health 99999 255 true', playerId, False)
        #     comp.SetCommand('/clear @s', playerId, False)

        elif args["message"] == "重置游戏":
            sta = False
            for item in self.map_op:
                if self.DC_check_nickname(playerId) == item:
                    self.restart()
                    sta = True
                    break
            if sta == False:
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§3仅超管可用！"}]}', playerId,
                                False)

        # elif args["message"] == "检测胸甲":
        #     comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
        #     BW_dict = comp.GetPlayerItem(serverApi.GetMinecraftEnum().ItemPosType.ARMOR, 1)
        #     print BW_dict
        #
        # elif args['message'] == "检测床":
        #     comp = serverApi.GetEngineCompFactory().CreateBlockInfo(self.playerlist[0]['id'])
        #     pos = (-75, 67, -129)
        #
        #     dimensionId = 2
        #     color = comp.GetBedColor(pos)
        #     print ("bed_li_check", color)
        #
        # elif args['message'] == "加载末地结构":
        #
        #     comp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId())
        #     temp = (-126, 7, -149)
        #
        #     status = comp.PlaceStructure(None, temp, "kssae:end_2", 2, 0)
        #     print ("### end_fix", status)

        elif args['message'] == "时间加":
            sta = False
            for item in self.map_op:
                if self.DC_check_nickname(playerId) == item:
                    self.bedwar_times += 200
                    sta = True
                    break
            if sta == False:
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§3仅超管可用！"}]}', playerId,
                                False)

        elif args['message'] == "传送到末地":
            sta = False
            for item in self.map_op:
                if self.DC_check_nickname(playerId) == item:
                    comp = serverApi.GetEngineCompFactory().CreateDimension(playerId)
                    comp.ChangePlayerDimension(2, (-62, 69, -139))
                    sta = True
                    break
            if sta == False:
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§3仅超管可用！"}]}', playerId,
                                False)
        elif args['message'] == '开始缩圈':
            self.suoquan_r = 330
            self.suoquan_sw = True

        # elif args['message'] == "蓝家修复":
        #     comp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId())
        #     temp = (-110, 59, 111)
        #
        #     status = comp.PlaceStructure(None, temp, "kssae:blue_2", 2, 0)
        #     print ("### blue_home_fix", status)
        #
        #
        # elif args['message'] == "紫家修复":
        #     comp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId())
        #     temp = (78, 59, 114)
        #
        #     status = comp.PlaceStructure(None, temp, "kssae:purple_2", 2, 0)
        #     print ("### purple_home_fix", status)
        #
        #     status = comp.PlaceStructure(None, temp, "kssae:purple_home", 2, 0)
        #     print ("### purple_home_fix", status)

        # elif args['message'] == "检测盔甲":
        #     for e in self.playerlist:
        #         comp = serverApi.GetEngineCompFactory().CreateItem(e['id'])
        #
        #         data = comp.GetPlayerItem(3, 0)['newItemName']
        #         data2 = comp.GetPlayerItem(3, 1)['newItemName']
        #         data3 = comp.GetPlayerItem(3, 2)['newItemName']
        #         data4 = comp.GetPlayerItem(3, 3)['newItemName']
        #         print ("### jiance",data,data2,data3,data4)

        elif args['message'] == "飞行模式":
            sta = False
            for item in self.map_op:
                if self.DC_check_nickname(playerId) == item:
                    comp = serverApi.GetEngineCompFactory().CreateFly(playerId)
                    comp.ChangePlayerFlyState(True)
                    sta = True
                    break
            if sta == False:
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§3仅超管可用！"}]}', playerId,
                                False)

        else:
            print "==== 不在判断内 ===="

    def sendmessagestoplayer(self, playerid, msg):
        comp = serverApi.GetEngineCompFactory().CreateMsg(playerid)
        comp.NotifyOneMessage(playerid, "test", "§c")
        serverApi.GetPlayerList()

    def callback_c(self, data):
        if data:
            # 在代码块下执行自己的业务逻辑
            print data
            print {i["key"]: i["value"] for i in data["entity"]["data"][0]['value']['entity']['data']}

            for i in data["entity"]["data"][0]['value']['entity']['data']:
                if len(i["key"]) != 0:
                    if len(i["value"]) != 0:
                        print "===== 获取到运营数据配置开始 ====="
                        print (i["key"], i["value"])
                        if i["key"] == "MyNotice":
                            self.MyNotice = i["value"]
                        elif i["key"] == "map_op":
                            self.map_op = i["value"]
                        elif i["key"] == "title_yellow":
                            self.title_yellow = i["value"]
                        elif i["key"] == "title_purple":
                            self.title_purple = i["value"]
                        elif i["key"] == "title_red":
                            self.title_red = i["value"]
                        elif i["key"] == "title_black":
                            self.title_black = i["value"]
                        elif i["key"] == "title_green":
                            self.title_green = i["value"]
                        print "===== 获取到运营数据配置结束 ====="
                else:
                    print "===== 获取运营数据失败 ====="

    # 函数名为Destroy才会被调用，在这个System被引擎回收的时候会调这个函数来销毁一些内容
    def Destroy(self):
        print "===== TutorialServerSystem Destroy ====="
        # 调用上面的反监听函数来销毁
        self.UnListenEvent()

    # 服务器tick每秒事件
    def OnScriptTickServer(self):
        self.tick += 1
        if len(self.event_list_tick) > 0:
            comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            deal = self.event_list_tick[0]
            self.event_list_tick.pop(0)
            comp.SetCommand(deal, False)
            print deal

        # if self.tick >= 15 and self.tick<30:
        #     if self.bedwar_switch == True:
        #         self.egg_road()


        if self.tick >= 30:
            if self.bedwar_switch == True:
                self.egg_road()
            self.tick_s += 1
            self.tick_s_59 += 1

            if self.bedwar_switch == True:
                self.bedwar_times += 1
                print "bedwar_times ==> " + str(self.bedwar_times)

            for evc in self.time_laters:
                time_now = time.time()
                print ("time_laters", evc['DEAD_TIME'], evc['EVENT_NAME'])
                if int(time_now) >= int(evc['DEAD_TIME']):
                    name_c = evc['EVENT_NAME']
                    if name_c == "hide_c":
                        self.hide_c()
                    elif name_c == "recover_status":
                        self.recover_status()
                    elif name_c == "kill_all_kill":
                        self.kill_all_kill()
                    elif name_c == "aev_tp":
                        self.aev_tp()
                    elif name_c == "aev_effect":
                        self.aev_effect()
                    elif name_c == "block_fix":
                        self.block_fix()
                    elif name_c == "effect_clear":
                        self.effect_clear()
                    elif name_c == "fly_check":
                        self.fly_check()
                    elif name_c == "clear_all":
                        self.clear_all()
                    elif name_c == "notice_all_restart":
                        self.notice_all_restart()
                    elif name_c == "all_tp_e":
                        self.all_tp_e()
                    elif name_c == "game_over_count":
                        self.game_over_count()
                    elif name_c == "game_over_add":
                        self.game_over_add()
                    elif name_c == "game_over_cz":
                        self.game_over_cz()
                    elif name_c == "restart":
                        self.restart()
                    elif name_c == "fix_more_p_b":
                        self.fix_more_p_b()
                    elif name_c == "restart_tp":
                        self.restart_tp()
                    elif name_c == "kill_all_su":
                        self.kill_all_su()
                    elif name_c == "switch_fa_eff":
                        self.switch_fa_eff()
                    elif name_c == "switch_fa_eff_health":
                        self.switch_fa_eff_health()
                    self.time_laters.remove(evc)

            self.tick_s_5 += 1
            self.tick_s_10 += 1
            self.tick_s_30 += 1
            # print "tick_s_5 ==> "+str(self.tick_s_5)
            print "tick_s_59 ==> " + str(self.tick_s_59)
            self.tick = 0

            comp = serverApi.GetEngineCompFactory().CreatePet(serverApi.GetLevelId())
            comp.Disable()

            self.match_player()

            self.match_start()

            self.times_1s_set()

            self.check_bed()

            self.check_game_over()

            if self.bedwar_switch == False:
                self.BW_notice_wait(self.ver, len(self.playerlist), len(self.BW_match_playerlist))
            else:
                self.BW_notice_game_start(self.ver)
                self.player_main()

            self.BW_def_playermenu_outworld()

            if len(self.dead_list) > 0:
                for e in self.dead_list:
                    id = e[0]
                    nickname = e[1]
                    team = e[2]
                    seconds = e[3]
                    if (seconds > 0):
                        self.dead_list.remove(e)
                        seconds -= 1
                        e[3] -= 1
                        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                        comp.SetCommand("/title @s title §l§e" + str(seconds) + "§l§2秒后复活", id, False)
                        print "============ effect ==="
                        comp.SetCommand('/effect @s invisibility 9999 255 true', id, False)
                        comp.SetCommand('/effect @s instant_health 9999 255 true', id, False)
                        comp.SetCommand('/effect @s weakness 99999 255 true', id, False)
                        comp.SetCommand('/effect @s instant_health 99999 255 true', id, False)
                        if self.event_all_jump == True:
                            com = "/effect @s jump_boost 9999 1 true"
                            comp.SetCommand(com, id, False)
                        if self.event_all_speed == True:
                            com = "/effect @s speed 9999 1 true"
                            comp.SetCommand(com, id, False)
                        comp.SetCommand('/clear @s', id, False)

                        self.dead_list.append(e)
                    if (seconds <= 0):
                        self.dead_list.remove(e)
                        print "=== effect clear " + str(id)
                        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                        comp.SetCommand("/effect @s clear", id, False)

                        comp = serverApi.GetEngineCompFactory().CreatePlayer(id)
                        comp.SetPlayerGameType(serverApi.GetMinecraftEnum().GameType.Survival)
                        # comp.SetCommand('/gamemode s @s', id, False)

                        # print ("===== 复合传送" + team)
                        # if team == "紫之队":
                        #     comp.ChangePlayerDimension(2, (91, 68, 140))
                        # if team == "绿之队":
                        #     comp.ChangePlayerDimension(2, (-62, 68, -139))
                        # if team == "蓝之队":
                        #     comp.ChangePlayerDimension(2, (-98, 68, 137))
                        # if team == "橙之队":
                        #     comp.ChangePlayerDimension(2, (96, 70, -136))

                        self.recover_tp_id = id
                        self.recover_tp_team = team
                        self.recover_status_id = id

                        # self.TIME_LATER_FUN("recover_tp",0)

                        print ("===== 复合传送" + self.recover_tp_team)
                        comp = serverApi.GetEngineCompFactory().CreateDimension(self.recover_tp_id)
                        if self.recover_tp_team == "紫之队":
                            comp.ChangePlayerDimension(2, (91, 68, 140))
                        if self.recover_tp_team == "绿之队":
                            comp.ChangePlayerDimension(2, (-62, 68, -139))
                        if self.recover_tp_team == "蓝之队":
                            comp.ChangePlayerDimension(2, (-98, 68, 137))
                        if self.recover_tp_team == "橙之队":
                            comp.ChangePlayerDimension(2, (96, 70, -136))

                        try:
                            self.BW_aev_playerlist.remove(id)
                        except:
                            pass

                        self.TIME_LATER_FUN("recover_status", 1)

            if self.bedwar_switch == True:
                if self.bedwar_times >= 0:
                    self.tick_iron_ingot += 1
                    self.tick_diamond += 1
                    self.tick_gold_ingot += 1
                    self.tick_emerald += 1

            if self.com_safe_switch == True:
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                comp.SetCommand('/gamerule commandblocksenabled true', False)
                comp.SetCommand('/title @a actionbar §6初云杯已开始报名，快来参赛~', False)

        if self.bedwar_switch == True:
            if self.bedwar_times >= 0:
                if self.tick_iron_ingot >= 5:
                    self.tick_iron_ingot = 0
                    a = self.xyz_re(self.bedwar_res_clone["iron_ingot"])
                    for f in self.bedwar_config_res_fresh_xyzs["iron_ingot"]:
                        # p = self.xyz_re(f)
                        # self.event_list_tick.append("/structure load 铁锭 "+p)
                        comp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId())
                        temp = self.xyz_re_temp(f)
                        comp.PlaceStructure(None, temp, "res:iron_ingot", 2, 0)

                if self.tick_gold_ingot >= 30:
                    self.tick_gold_ingot = 0
                    a = self.xyz_re(self.bedwar_res_clone["gold_ingot"])
                    for f in self.bedwar_config_res_fresh_xyzs["gold_ingot"]:
                        # p = self.xyz_re(f)
                        # self.event_list_tick.append("/structure load 金锭 " + p)
                        comp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId())
                        temp = self.xyz_re_temp(f)
                        comp.PlaceStructure(None, temp, "res:gold_ingot", 2, 0)

                if self.tick_diamond >= 60:
                    self.tick_diamond = 0
                    a = self.xyz_re(self.bedwar_res_clone["diamond"])
                    for f in self.bedwar_config_res_fresh_xyzs["diamond"]:
                        # p = self.xyz_re(f)
                        # self.event_list_tick.append("/structure load 钻石 " + p)
                        comp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId())
                        temp = self.xyz_re_temp(f)
                        comp.PlaceStructure(None, temp, "res:diamond", 2, 0)

                if self.tick_emerald >= 100:
                    self.tick_emerald = 0
                    a = self.xyz_re(self.bedwar_res_clone["emerald"])
                    for f in self.bedwar_config_res_fresh_xyzs["emerald"]:
                        # p = self.xyz_re(f)
                        # self.event_list_tick.append("/structure load 绿宝石 " + p)
                        comp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId())
                        temp = self.xyz_re_temp(f)
                        comp.PlaceStructure(None, temp, "res:emerald", 2, 0)

        if self.tick_s >= 60:
            self.tick_m += 1
            self.tick_s = 0

        if self.tick_s_5 >= 5:
            self.tick_s_5 = 0

            if self.bedwar_switch == True:
                if self.create_sw_str <= 3:
                    self.create_sw_str += 1
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    comp.SetCommand("/kill @e[name=箱子,x=3,y=1,z=-4,r=2]", False)
                    comp.SetCommand("/structure save 铁锭 3 1 -4 3 1 -4", False)

                    comp.SetCommand("/kill @e[name=箱子,x=3,y=2,z=-2,r=2]", False)
                    comp.SetCommand("/structure save 金锭 3 1 -2 3 1 -2", False)

                    comp.SetCommand("/kill @e[name=箱子,x=3,y=1,z=0,r=2]", False)
                    comp.SetCommand("/structure save 钻石 3 1 0 3 1 0", False)

                    comp.SetCommand("/kill @e[name=箱子,x=3,y=1,z=2,r=2]", False)
                    comp.SetCommand("/structure save 绿宝石 3 1 2 3 1 2", False)

            self.times_5s_set()

        if self.tick_s_10 >= 10:
            self.tick_s_10 = 0
            self.mingxie()
            # self.times_10s_set()

        if self.tick_s_30 >= 30:
            self.tick_s_30 = 0
            self.times_30s_set()

        if self.tick_s_59 >= 59:
            self.tick_s_59 = 0

        if self.tick_s_59 == 58:
            self.tick_s_59 += 1
            # comp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId())
            # comp.SetNotifyMsg(self.MyNotice)
            # httpComp = compFactory.CreateHttp(serverApi.GetLevelId())
            # # 返回来自开发者平台的运营管理配置中配置的数据。注意：每次在开发者平台提交的JSON配置数据会顶替掉上一次的配置信息。
            # httpComp.LobbyGetStorage(self.callback_c, 0, ['op_config'])

    # 服务器10秒事件
    def times_10s_set(self):
        if self.bedwar_switch:
            # comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #
            # comp.SetCommand('/tp @e[type=kssae:entity] -4 2 0', False)
            # comp.SetCommand('/tp @e[type=kssae:entity_1] -4 2 0', False)
            # comp.SetCommand('/tp @e[type=kssae:entity_2] -4 2 0', False)
            # comp.SetCommand('/tp @e[type=kssae:entity_3] -4 2 0', False)
            # comp.SetCommand('/tp @e[type=kssae:entity_4] -4 2 0', False)
            # comp.SetCommand('/tp @e[type=kssae:entity_5] -4 2 0', False)

            self.TIME_LATER_FUN("kill_all_kill", 1)

    # 服务器30秒事件
    def times_30s_set(self):
        # self.res_cr_safe()

        if self.bedwar_switch:
            # comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            #
            # comp.SetCommand('/tp @e[type=kssae:entity] -4 2 0', False)
            # comp.SetCommand('/tp @e[type=kssae:entity_1] -4 2 0', False)
            # comp.SetCommand('/tp @e[type=kssae:entity_2] -4 2 0', False)
            # comp.SetCommand('/tp @e[type=kssae:entity_3] -4 2 0', False)
            # comp.SetCommand('/tp @e[type=kssae:entity_4] -4 2 0', False)
            # comp.SetCommand('/tp @e[type=kssae:entity_5] -4 2 0', False)

            self.TIME_LATER_FUN("kill_all_kill", 1)

    # 服务器1秒事件
    def times_1s_set(self):
        self.arr_set(self.playerlist)

        self.BW_match_playerlist = list(set(self.BW_match_playerlist))
        self.bedwar_teamslist_purple_id = list(set(self.bedwar_teamslist_purple_id))
        self.bedwar_teamslist_blue_id = list(set(self.bedwar_teamslist_blue_id))
        self.bedwar_teamslist_green_id = list(set(self.bedwar_teamslist_green_id))
        self.bedwar_teamslist_orange_id = list(set(self.bedwar_teamslist_orange_id))
        self.BW_aev_playerlist = list(set(self.BW_aev_playerlist))
        self.playerlist_new = list(set(self.playerlist_new))

        # print self.BW_match_playerlist
        # print self.BW_aev_playerlist

        print self.bedwar_teamslist_green_id
        print self.bedwar_teamslist_orange_id
        print self.bedwar_teamslist_purple_id
        print self.bedwar_teamslist_blue_id

        # 定义两个数组
        list1 = self.BW_match_playerlist
        list2 = self.BW_aev_playerlist

        # 将数组转换为集合
        set1 = set(list1)
        set2 = set(list2)

        # 使用 intersection() 函数求两个集合的交集
        intersection_set = set1.intersection(set2)

        # 输出交集结果
        if len(intersection_set)<>0:
            for i in intersection_set:
                comp = serverApi.GetEngineCompFactory().CreateDimension(i)
                comp.ChangePlayerDimension(0, (-112, 120, -138))
                self.BW_match_playerlist.remove(i)
                self.BW_aev_playerlist.remove(i)


        # 将数组转换为集合 === 1
        set1 = set(self.bedwar_teamslist_blue_id)
        set2 = set(self.bedwar_teamslist_green_id)

        # 使用 intersection() 函数求两个集合的交集
        intersection_set = set1.intersection(set2)

        # 输出交集结果
        if len(intersection_set) <> 0:
            for i in intersection_set:
                comp = serverApi.GetEngineCompFactory().CreateDimension(i)
                comp.ChangePlayerDimension(0, (-112, 120, -138))
                comp = serverApi.GetEngineCompFactory().CreatePlayer(i)
                suc = comp.SetPlayerRespawnPos((-112, 120, -138), 0)
                try:
                    self.bedwar_teamslist_blue_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_green_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_purple_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_orange_id.remove(i)
                except:
                    pass



        # 将数组转换为集合  === 2
        set1 = set(self.bedwar_teamslist_blue_id)
        set2 = set(self.bedwar_teamslist_orange_id)

        # 使用 intersection() 函数求两个集合的交集
        intersection_set = set1.intersection(set2)

        # 输出交集结果
        if len(intersection_set) <> 0:
            for i in intersection_set:
                comp = serverApi.GetEngineCompFactory().CreateDimension(i)
                comp.ChangePlayerDimension(0, (-112, 120, -138))
                comp = serverApi.GetEngineCompFactory().CreatePlayer(i)
                suc = comp.SetPlayerRespawnPos((-112, 120, -138), 0)
                try:
                    self.bedwar_teamslist_blue_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_green_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_purple_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_orange_id.remove(i)
                except:
                    pass

        # 将数组转换为集合 === 3
        set1 = set(self.bedwar_teamslist_blue_id)
        set2 = set(self.bedwar_teamslist_purple_id)

        # 使用 intersection() 函数求两个集合的交集
        intersection_set = set1.intersection(set2)

        # 输出交集结果
        if len(intersection_set) <> 0:
            for i in intersection_set:
                comp = serverApi.GetEngineCompFactory().CreateDimension(i)
                comp.ChangePlayerDimension(0, (-112, 120, -138))
                comp = serverApi.GetEngineCompFactory().CreatePlayer(i)
                suc = comp.SetPlayerRespawnPos((-112, 120, -138), 0)
                try:
                    self.bedwar_teamslist_blue_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_green_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_purple_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_orange_id.remove(i)
                except:
                    pass

        # 将数组转换为集合  === 4
        set1 = set(self.bedwar_teamslist_green_id)
        set2 = set(self.bedwar_teamslist_orange_id)

        # 使用 intersection() 函数求两个集合的交集
        intersection_set = set1.intersection(set2)

        # 输出交集结果
        if len(intersection_set) <> 0:
            for i in intersection_set:
                comp = serverApi.GetEngineCompFactory().CreateDimension(i)
                comp.ChangePlayerDimension(0, (-112, 120, -138))
                comp = serverApi.GetEngineCompFactory().CreatePlayer(i)
                suc = comp.SetPlayerRespawnPos((-112, 120, -138), 0)
                try:
                    self.bedwar_teamslist_blue_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_green_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_purple_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_orange_id.remove(i)
                except:
                    pass

        # 将数组转换为集合 === 5
        set1 = set(self.bedwar_teamslist_green_id)
        set2 = set(self.bedwar_teamslist_purple_id)

        # 使用 intersection() 函数求两个集合的交集
        intersection_set = set1.intersection(set2)

        # 输出交集结果
        if len(intersection_set) <> 0:
            for i in intersection_set:
                comp = serverApi.GetEngineCompFactory().CreateDimension(i)
                comp.ChangePlayerDimension(0, (-112, 120, -138))
                comp = serverApi.GetEngineCompFactory().CreatePlayer(i)
                suc = comp.SetPlayerRespawnPos((-112, 120, -138), 0)
                try:
                    self.bedwar_teamslist_blue_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_green_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_purple_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_orange_id.remove(i)
                except:
                    pass

        # 将数组转换为集合  === 6
        set1 = set(self.bedwar_teamslist_orange_id)
        set2 = set(self.bedwar_teamslist_purple_id)

        # 使用 intersection() 函数求两个集合的交集
        intersection_set = set1.intersection(set2)

        # 输出交集结果
        if len(intersection_set) <> 0:
            for i in intersection_set:
                comp = serverApi.GetEngineCompFactory().CreateDimension(i)
                comp.ChangePlayerDimension(0, (-112, 120, -138))
                comp = serverApi.GetEngineCompFactory().CreatePlayer(i)
                suc = comp.SetPlayerRespawnPos((-112, 120, -138), 0)
                try:
                    self.bedwar_teamslist_blue_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_green_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_purple_id.remove(i)
                except:
                    pass
                try:
                    self.bedwar_teamslist_orange_id.remove(i)
                except:
                    pass




        comp = serverApi.GetEngineCompFactory().CreateBlockInfo(self.playerlist[0]['id'])
        pos = (-115, 104, -135)
        dimensionId = 0
        suc = comp.SetSignBlockText(pos, "§e§l>>>\n§d§l感谢您的下载和游玩\n§c§l祝您游玩愉快！", dimensionId)
        pos = (-115, 104, -136)
        dimensionId = 0
        suc = comp.SetSignBlockText(pos, "§d§l《初云杯大赛》\n§d§l已开始报名！\n§c§l有奖杯和小礼品！", dimensionId)
        pos = (-115, 104, -137)
        dimensionId = 0
        suc = comp.SetSignBlockText(pos, "§e§l【交流群】\n§e§l881304734\n§d§l一起建造和学习！", dimensionId)

        pos = (-115, 105, -135)
        dimensionId = 0
        suc = comp.SetSignBlockText(pos, "§d§l地图作者：\n§d§l@kevin_hh123\n§d§l（哔哩哔哩）", dimensionId)
        pos = (-115, 105, -136)
        dimensionId = 0
        suc = comp.SetSignBlockText(pos, "§d§l玩法开发：\n§d§l@MC初云工作室\n§d§l（哔哩哔哩）", dimensionId)
        pos = (-115, 105, -137)
        dimensionId = 0
        suc = comp.SetSignBlockText(pos, "§d§l光影提供：\n§d§l@重生的楚楚\n§d§l《重生像素光影》", dimensionId)

        pos = (-115, 106, -136)
        dimensionId = 0
        suc = comp.SetSignBlockText(pos, "§d§l打击作弊行为！\n§c§l欢迎随时入群举办！！\n§a§l严惩加黑名单！！！", dimensionId)


        if self.bedwar_switch == False:
            comp = serverApi.GetEngineCompFactory().CreateBlockInfo(self.playerlist[0]['id'])
            pos = (-112, 105, -136)
            dimensionId = 0
            suc = comp.SetSignBlockText(pos, "§e§l✔✔✔\n§c§l【游戏可加入】\n§d§l请尽快匹配！", dimensionId)

        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        context = '/kill @e[name=蓝队]'
        comp.SetCommand(context, False)
        context = '/kill @e[name=绿队]'
        comp.SetCommand(context, False)
        context = '/kill @e[name=橙队]'
        comp.SetCommand(context, False)
        context = '/kill @e[name=紫队]'
        comp.SetCommand(context, False)
        context = '/kill @e[name=紫色羊毛]'
        comp.SetCommand(context, False)
        context = '/kill @e[name=黄绿色羊毛]'
        comp.SetCommand(context, False)
        context = '/kill @e[name=橙色羊毛]'
        comp.SetCommand(context, False)
        context = '/kill @e[name=淡蓝色羊毛]'
        comp.SetCommand(context, False)
        context = '/kill @e[type=enderman]'
        comp.SetCommand(context, False)

        comp = serverApi.GetEngineCompFactory().CreateMobSpawn(serverApi.GetLevelId())
        comp.SpawnCustomModule(9, 0, 38, 10, 0, 0, 1)

        print ("1s")

        if self.suoquan_sw == True:
            self.suoquan()

    # 坐标重定义
    def xyz_re(self, xyz=[0, 0, 0]):
        return str(xyz[0]) + " " + str(xyz[1]) + " " + str(xyz[2])

    # 坐标重定义2
    def xyz_re_temp(self, xyz=[0, 0, 0]):
        return (xyz[0], xyz[1], xyz[2])

    # 数组判断
    def judge(self, n):
        n1 = str(n)
        n2 = n1.split('.')
        if n2[1] == '0':
            return True
        else:
            return False

    # 获取玩家昵称
    def DC_check_nickname(self, playerid):
        for e in self.playerlist:
            if e['id'] == playerid:
                return e['name']
                break
        return ""

    # 获取玩家队伍["系统", "§e"]
    def DC_check_teamname(self, playerid):
        check_bool = False

        if check_bool == False:
            for e in self.bedwar_teamslist_green_id:
                if e == playerid:
                    check_bool = True
                    return ["绿之队", "§a"]
                    break

        if check_bool == False:
            for e in self.bedwar_teamslist_orange_id:
                if e == playerid:
                    check_bool = True
                    return ["橙之队", "§6"]
                    break

        if check_bool == False:
            for e in self.bedwar_teamslist_blue_id:
                if e == playerid:
                    check_bool = True
                    return ["蓝之队", "§3"]
                    break

        if check_bool == False:
            for e in self.bedwar_teamslist_purple_id:
                if e == playerid:
                    check_bool = True
                    return ["紫之队", "§9"]
                    break

        if check_bool == False:
            return ["系统", "§e"]

    # 物品栏菜单
    def BW_def_playermenu_outworld(self):

        if self.bedwar_switch == False:  # 游戏没有开始
            for e in self.playerlist:

                try:
                    arr = self.BW_match_playerlist
                    new_arr = []
                    for i in arr:
                        if i not in new_arr:
                            new_arr.append(i)
                    self.BW_match_playerlist = new_arr
                    print self.BW_match_playerlist.index(e['id'])

                    a = True
                except:
                    a = False
                    pass

                try:
                    arr = self.BW_aev_playerlist
                    new_arr = []
                    for i in arr:
                        if i not in new_arr:
                            new_arr.append(i)
                    self.BW_aev_playerlist = new_arr
                    print self.BW_aev_playerlist.index(e['id'])

                    b = True
                except:
                    b = False
                    pass

                if b == True:
                    playerId = e['id']
                    itemDict = {
                        'itemName': 'minecraft:golden_chestplate',
                        'count': 1,
                        'enchantData': [],
                        'auxValue': 0,
                        'customTips': '§e 开始匹配 §r',
                        'extraId': 'abc',
                        'userData': {},
                    }
                    comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                    comp.SpawnItemToPlayerInv(itemDict, playerId, 2)

                    itemDict = {
                        'itemName': 'minecraft:barrier',
                        'count': 1,
                        'enchantData': [],
                        'auxValue': 0,
                        'customTips': '§c 返回大厅（退出观战） §r',
                        'extraId': 'abcd',
                        'userData': {},
                    }
                    comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                    comp.SpawnItemToPlayerInv(itemDict, playerId, 6)

                    itemDict = {
                        'itemName': 'minecraft:air',
                        'count': 1,
                        'enchantData': [],
                        'auxValue': 0,
                        'customTips': '',
                        'extraId': 'abc',
                        'userData': {},
                    }
                    comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                    comp.SpawnItemToPlayerInv(itemDict, playerId, 0)

                    itemDict = {
                        'itemName': 'minecraft:air',
                        'count': 1,
                        'enchantData': [],
                        'auxValue': 0,
                        'customTips': '',
                        'extraId': 'abc',
                        'userData': {},
                    }
                    comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                    comp.SpawnItemToPlayerInv(itemDict, playerId, 1)

                    itemDict = {
                        'itemName': 'minecraft:air',
                        'count': 1,
                        'enchantData': [],
                        'auxValue': 0,
                        'customTips': '',
                        'extraId': 'abc',
                        'userData': {},
                    }
                    comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                    comp.SpawnItemToPlayerInv(itemDict, playerId, 3)

                    itemDict = {
                        'itemName': 'minecraft:enchanted_book',
                        'count': 1,
                        'enchantData': [],
                        'auxValue': 0,
                        'customTips': '§3 玩法攻略 §r',
                        'extraId': 'abc',
                        'userData': {},
                    }
                    comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                    comp.SpawnItemToPlayerInv(itemDict, playerId, 4)

                    itemDict = {
                        'itemName': 'minecraft:air',
                        'count': 1,
                        'enchantData': [],
                        'auxValue': 0,
                        'customTips': '',
                        'extraId': 'abc',
                        'userData': {},
                    }
                    comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                    comp.SpawnItemToPlayerInv(itemDict, playerId, 5)

                    itemDict = {
                        'itemName': 'minecraft:air',
                        'count': 1,
                        'enchantData': [],
                        'auxValue': 0,
                        'customTips': '',
                        'extraId': 'abc',
                        'userData': {},
                    }
                    comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                    comp.SpawnItemToPlayerInv(itemDict, playerId, 7)

                    itemDict = {
                        'itemName': 'minecraft:air',
                        'count': 1,
                        'enchantData': [],
                        'auxValue': 0,
                        'customTips': '',
                        'extraId': 'abc',
                        'userData': {},
                    }
                    comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                    comp.SpawnItemToPlayerInv(itemDict, playerId, 8)
                else:

                    if a == True:
                        playerId = e['id']
                        itemDict = {
                            'itemName': 'kssae:orange_team_armor_main',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '§e 橙之队 §r',
                            'extraId': 'abc',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 0)

                        itemDict = {
                            'itemName': 'kssae:blue_team_armor_main',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '§3 蓝之队 §r',
                            'extraId': 'abcd',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 2)

                        itemDict = {
                            'itemName': 'kssae:green_team_armor_main',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '§b 绿之队 §r',
                            'extraId': 'abc',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 4)

                        itemDict = {
                            'itemName': 'kssae:purple_team_armor_main',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '§9 紫之队 §r',
                            'extraId': 'abc',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 6)

                        itemDict = {
                            'itemName': 'minecraft:barrier',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '§c 退出匹配 §r',
                            'extraId': 'abc',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 8)

                        itemDict = {
                            'itemName': 'minecraft:air',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '',
                            'extraId': 'abc',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 1)

                        itemDict = {
                            'itemName': 'minecraft:air',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '',
                            'extraId': 'abc',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 3)

                        itemDict = {
                            'itemName': 'minecraft:air',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '',
                            'extraId': 'abc',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 5)

                        itemDict = {
                            'itemName': 'minecraft:air',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '',
                            'extraId': 'abc',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 7)
                    if a == False:
                        playerId = e['id']
                        itemDict = {
                            'itemName': 'minecraft:golden_chestplate',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '§e 开始匹配 §r',
                            'extraId': 'abc',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 2)

                        itemDict = {
                            'itemName': 'minecraft:redstone',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '§9 观战 §r',
                            'extraId': 'abcd',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 6)

                        itemDict = {
                            'itemName': 'minecraft:air',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '',
                            'extraId': 'abc',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 0)

                        itemDict = {
                            'itemName': 'minecraft:air',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '',
                            'extraId': 'abc',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 1)

                        itemDict = {
                            'itemName': 'minecraft:air',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '',
                            'extraId': 'abc',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 3)

                        itemDict = {
                            'itemName': 'minecraft:enchanted_book',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '§3 玩法攻略 §r',
                            'extraId': 'abc',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 4)

                        itemDict = {
                            'itemName': 'minecraft:air',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '',
                            'extraId': 'abc',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 5)

                        itemDict = {
                            'itemName': 'minecraft:air',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '',
                            'extraId': 'abc',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 7)

                        itemDict = {
                            'itemName': 'minecraft:air',
                            'count': 1,
                            'enchantData': [],
                            'auxValue': 0,
                            'customTips': '',
                            'extraId': 'abc',
                            'userData': {},
                        }
                        comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                        comp.SpawnItemToPlayerInv(itemDict, playerId, 8)

        if self.bedwar_switch == True:  # 游戏开始
            for e in self.playerlist_new:
                playerId = e['id']
                itemDict = {
                    'itemName': 'minecraft:golden_chestplate',
                    'count': 1,
                    'enchantData': [],
                    'auxValue': 0,
                    'customTips': '§e 开始匹配 §r',
                    'extraId': 'abc',
                    'userData': {},
                }
                comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                comp.SpawnItemToPlayerInv(itemDict, playerId, 2)

                itemDict = {
                    'itemName': 'minecraft:redstone',
                    'count': 1,
                    'enchantData': [],
                    'auxValue': 0,
                    'customTips': '§9 观战 §r',
                    'extraId': 'abcd',
                    'userData': {},
                }
                comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                comp.SpawnItemToPlayerInv(itemDict, playerId, 6)

                itemDict = {
                    'itemName': 'minecraft:air',
                    'count': 1,
                    'enchantData': [],
                    'auxValue': 0,
                    'customTips': '',
                    'extraId': 'abc',
                    'userData': {},
                }
                comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                comp.SpawnItemToPlayerInv(itemDict, playerId, 0)

                itemDict = {
                    'itemName': 'minecraft:air',
                    'count': 1,
                    'enchantData': [],
                    'auxValue': 0,
                    'customTips': '',
                    'extraId': 'abc',
                    'userData': {},
                }
                comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                comp.SpawnItemToPlayerInv(itemDict, playerId, 1)

                itemDict = {
                    'itemName': 'minecraft:air',
                    'count': 1,
                    'enchantData': [],
                    'auxValue': 0,
                    'customTips': '',
                    'extraId': 'abc',
                    'userData': {},
                }
                comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                comp.SpawnItemToPlayerInv(itemDict, playerId, 3)

                itemDict = {
                    'itemName': 'minecraft:enchanted_book',
                    'count': 1,
                    'enchantData': [],
                    'auxValue': 0,
                    'customTips': '§3 玩法攻略 §r',
                    'extraId': 'abc',
                    'userData': {},
                }
                comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                comp.SpawnItemToPlayerInv(itemDict, playerId, 4)

                itemDict = {
                    'itemName': 'minecraft:air',
                    'count': 1,
                    'enchantData': [],
                    'auxValue': 0,
                    'customTips': '',
                    'extraId': 'abc',
                    'userData': {},
                }
                comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                comp.SpawnItemToPlayerInv(itemDict, playerId, 5)

                itemDict = {
                    'itemName': 'minecraft:air',
                    'count': 1,
                    'enchantData': [],
                    'auxValue': 0,
                    'customTips': '',
                    'extraId': 'abc',
                    'userData': {},
                }
                comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                comp.SpawnItemToPlayerInv(itemDict, playerId, 7)

                itemDict = {
                    'itemName': 'minecraft:air',
                    'count': 1,
                    'enchantData': [],
                    'auxValue': 0,
                    'customTips': '',
                    'extraId': 'abc',
                    'userData': {},
                }
                comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
                comp.SpawnItemToPlayerInv(itemDict, playerId, 8)

    # 玩家匹配检测
    def match_player(self):
        player_num = len(self.BW_match_playerlist)

        if player_num >= 2:
            self.match_switch = True
        elif player_num < 2:
            self.match_switch = False
            self.match_scends = 60

    # 玩家开始匹配（倒计时结束）
    def match_start(self):
        if self.match_switch == True:
            self.match_scends -= 1
            print self.match_scends
            if (self.match_scends <= 0):
                # 游戏开始
                self.match_switch = False
                print (self.match_switch)
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                comp.SetCommand('/title @a title §b游戏开始！', False)

                self.TIME_LATER_FUN("aev_tp", 4)

                BW_match_playerlist = self.BW_match_playerlist

                if len(BW_match_playerlist) >= 2:
                    print "=== None 开始分队V2"
                    players = BW_match_playerlist
                    teams = self.assign_teams(players, 4)
                    print("@@@teams", teams)
                    self.bedwar_teamslist_orange_id = teams[0]
                    self.bedwar_teamslist_green_id = teams[1]
                    self.bedwar_teamslist_purple_id = teams[2]
                    self.bedwar_teamslist_blue_id = teams[3]

                print "==== blue_team"
                print self.bedwar_teamslist_blue_id
                print "==== green_team"
                print self.bedwar_teamslist_green_id
                print "==== orange_team"
                print self.bedwar_teamslist_orange_id
                print "==== purple_team"
                print self.bedwar_teamslist_purple_id

                print self.BW_match_playerlist
                for g in self.BW_match_playerlist:
                    print "=== BW_match_playerlist"
                    print self.BW_match_playerlist
                    comp = serverApi.GetEngineCompFactory().CreateDimension(g)
                    print self.DC_check_teamname(g)[0]
                    if self.DC_check_teamname(g)[0] == "紫之队":
                        comp.ChangePlayerDimension(2, (91, 69, 140))
                        comp = serverApi.GetEngineCompFactory().CreatePlayer(g)
                        suc = comp.SetPlayerRespawnPos((91, 69, 140), 2)
                    if self.DC_check_teamname(g)[0] == "绿之队":
                        comp.ChangePlayerDimension(2, (-62, 69, -139))
                        comp = serverApi.GetEngineCompFactory().CreatePlayer(g)
                        suc = comp.SetPlayerRespawnPos((-62, 69, -139), 2)
                    if self.DC_check_teamname(g)[0] == "蓝之队":
                        comp.ChangePlayerDimension(2, (-98, 69, 137))
                        comp = serverApi.GetEngineCompFactory().CreatePlayer(g)
                        suc = comp.SetPlayerRespawnPos((-98, 69, 137), 2)
                    if self.DC_check_teamname(g)[0] == "橙之队":
                        comp.ChangePlayerDimension(2, (96, 71, -136))
                        comp = serverApi.GetEngineCompFactory().CreatePlayer(g)
                        suc = comp.SetPlayerRespawnPos((96, 71, -136), 2)
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    comp.SetCommand('/clear @s', g, False)

                    comp = serverApi.GetEngineCompFactory().CreatePlayer(g)
                    comp.SetPlayerGameType(serverApi.GetMinecraftEnum().GameType.Survival)

                self.BW_match_playerlist = []

                self.BW_game_start()

            if (self.match_scends > 0 and self.match_scends <= 5):
                # 游戏开始
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                comp.SetCommand('/title @a subtitle §c' + str(self.match_scends) + "秒", False)
                comp.SetCommand('/title @a title §e游戏开始倒计时！', False)

            if (self.match_scends == 10):
                # 游戏开始
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                comp.SetCommand('/title @a subtitle §c请穿戴金胸甲参与游戏', False)
                comp.SetCommand('/title @a title §e游戏还剩10s开始！', False)

            if (self.match_scends == 20):
                # 游戏开始
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                comp.SetCommand('/title @a subtitle §c请穿戴金胸甲参与游戏', False)
                comp.SetCommand('/title @a title §e游戏还剩20秒开始！', False)

            if (self.match_scends == 30):
                # 游戏开始
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                comp.SetCommand('/title @a subtitle §c请穿戴金胸甲参与游戏', False)
                comp.SetCommand('/title @a title §e游戏还剩30秒开始！', False)

            if (self.match_scends == 59):
                # 游戏开始
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                comp.SetCommand('/title @a subtitle §c请穿戴金胸甲参与游戏', False)
                comp.SetCommand('/title @a title §e游戏开始60秒匹配！', False)

    # 数组查重
    def arr_set(self, arr):
        new_arr = []
        for i in arr:
            if i not in new_arr:
                new_arr.append(i)
        arr = new_arr

    # 服务器5秒事件
    def times_5s_set(self):
        if self.bedwar_switch == False:
            self.fly_check()


        if self.bedwar_switch == True:
            orange = "§6§l[橙]：§6 " + ""
            blue = "§3§l[蓝]：§3 " + ""
            purple = "§9§l[紫]：§9 " + ""
            green = "§a§l[绿]：§a " + ""

            for e in self.bedwar_teamslist_orange_id:
                nickname = self.DC_check_nickname(e)
                orange = orange + nickname + " "

            for e in self.bedwar_teamslist_blue_id:
                nickname = self.DC_check_nickname(e)
                blue = blue + nickname + " "

            for e in self.bedwar_teamslist_purple_id:
                nickname = self.DC_check_nickname(e)
                purple = purple + nickname + " "

            for e in self.bedwar_teamslist_green_id:
                nickname = self.DC_check_nickname(e)
                green = green + nickname + " "

            gt = orange + "\n" + blue + "\n" + purple + "\n" + green
            g = {"text": gt}

            self.BroadCastEventTest(g)

            for i in self.BW_aev_playerlist:
                playerId_1 = i
                itemDict = {
                    'itemName': 'minecraft:air',
                    'count': 1,
                    'enchantData': [],
                    'auxValue': 0,
                    'customTips': '',
                    'extraId': 'abc',
                    'userData': {},
                }
                comp = serverApi.GetEngineCompFactory().CreateItem(playerId_1)
                comp.SpawnItemToPlayerInv(itemDict, playerId_1, 0)
                comp.SpawnItemToPlayerInv(itemDict, playerId_1, 1)
                comp.SpawnItemToPlayerInv(itemDict, playerId_1, 2)
                comp.SpawnItemToPlayerInv(itemDict, playerId_1, 3)
                comp.SpawnItemToPlayerInv(itemDict, playerId_1, 4)
                comp.SpawnItemToPlayerInv(itemDict, playerId_1, 5)
                comp.SpawnItemToPlayerInv(itemDict, playerId_1, 6)
                comp.SpawnItemToPlayerInv(itemDict, playerId_1, 7)
                comp.SpawnItemToPlayerInv(itemDict, playerId_1, 8)

        for e in self.playerlist:
            comp = serverApi.GetEngineCompFactory().CreatePlayer(e['id'])
            comp.SetPlayerHunger(20)

        # if self.bedwar_switch == False:
        #     self.BW_notice_wait(self.ver,len(self.playerlist),len(self.BW_match_playerlist))
        # else:
        #     self.BW_notice_game_start(self.ver)
        ###游戏规则字典说明
        c_gameRuleDict = {}
        if self.bedwar_switch == True:
            c_gameRuleDict = {
                'option_info': {
                    'pvp': True,  # 玩家伤害
                    'show_coordinates': False,  # 显示坐标
                    'fire_spreads': False,  # 火焰蔓延
                    'tnt_explodes': False,  # tnt爆炸
                    'mob_loot': False,  # 生物战利品
                    'natural_regeneration': True,  # 自然生命恢复
                    'tile_drops': True,  # 方块掉落
                    'immediate_respawn': True  # 立即重生
                },
                'cheat_info': {
                    'enable': True,  # 是否开启作弊
                    'always_day': False,  # 终为白日
                    'mob_griefing': False,  # 生物破坏方块
                    'keep_inventory': False,  # 保留物品栏
                    'weather_cycle': False,  # 天气更替
                    'mob_spawn': False,  # 生物生成
                    'entities_drop_loot': False,  # 实体掉落
                    'daylight_cycle': True,  # 开启昼夜交替
                    'command_blocks_enabled': True,  # 启用方块命令
                }
            }
        else:
            c_gameRuleDict = {
                'option_info': {
                    'pvp': False,  # 玩家伤害
                    'show_coordinates': False,  # 显示坐标
                    'fire_spreads': False,  # 火焰蔓延
                    'tnt_explodes': False,  # tnt爆炸
                    'mob_loot': False,  # 生物战利品
                    'natural_regeneration': True,  # 自然生命恢复
                    'tile_drops': True,  # 方块掉落
                    'immediate_respawn': True  # 立即重生
                },
                'cheat_info': {
                    'enable': True,  # 是否开启作弊
                    'always_day': False,  # 终为白日
                    'mob_griefing': False,  # 生物破坏方块
                    'keep_inventory': False,  # 保留物品栏
                    'weather_cycle': False,  # 天气更替
                    'mob_spawn': False,  # 生物生成
                    'entities_drop_loot': False,  # 实体掉落
                    'daylight_cycle': True,  # 开启昼夜交替
                    'command_blocks_enabled': True,  # 启用方块命令
                }
            }

        comp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId())
        comp.SetGameRulesInfoServer(c_gameRuleDict)
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand('/weather clear', False)

        # comp.SetCommand('/kill @e[type=kssae:entity]', False)
        # comp.SetCommand('/kill @e[type=kssae:entity_1]', False)
        # comp.SetCommand('/kill @e[type=kssae:entity_2]', False)
        # comp.SetCommand('/kill @e[type=kssae:entity_3]', False)
        # comp.SetCommand('/kill @e[type=kssae:entity_4]', False)
        # comp.SetCommand('/kill @e[type=kssae:entity_5]', False)
        #
        # comp.SetCommand('/summon kssae:entity 96 97 138', False)
        # comp.SetCommand('/summon kssae:entity -94 67 135', False)
        # comp.SetCommand('/summon kssae:entity -67 67 -140', False)
        # comp.SetCommand('/summon kssae:entity 89 70 -135', False)
        #
        # comp.SetCommand('/summon kssae:entity_1 87 69 140', False)
        # comp.SetCommand('/summon kssae:entity_1 -102 69 135', False)
        # comp.SetCommand('/summon kssae:entity_1 -66 67 -142', False)
        # comp.SetCommand('/summon kssae:entity_1 94 68 -137 ', False)
        #
        # comp.SetCommand('/summon kssae:entity_2 -92 67 136', False)
        # comp.SetCommand('/summon kssae:entity_3 -68 67 -139', False)
        # comp.SetCommand('/summon kssae:entity_4 91 69 -134', False)
        # comp.SetCommand('/summon kssae:entity_5 97 66 139', False)

        self.TIME_LATER_FUN("aev_effect", 8)

        # if len(self.BW_aev_playerlist) >0:
        #     print (self.BW_aev_playerlist)
        #     for fef in self.BW_aev_playerlist:
        #         comp = serverApi.GetEngineCompFactory().CreateItem(fef)
        #         s = comp.GetPlayerItem(serverApi.GetMinecraftEnum().ItemPosType.INVENTORY, 0)
        #         if s != None:
        #             comp = serverApi.GetEngineCompFactory().CreatePlayer(fef)
        #             suc = comp.SetPlayerRespawnPos((0, 80, 0), 2)
        #
        #             comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        #             comp.SetCommand("/kill @s", fef, False)

    # 游戏重置
    def restart(self):



        self.suoquan_r = 330
        self.suoquan_sw = False
        self.match_scends = 60
        self.event_all_speed = False
        self.event_all_jump = False
        self.event_all_power = False

        self.dr_times = 0
        self.dr_switch = False
        self.hide_id = 0

        self.tick = 0
        self.tick_s = 0
        self.tick_s_5 = 0
        self.tick_s_59 = 0
        self.tick_m = 0
        self.tick_s_10 = 0

        self.time_laters = []

        self.BW_bed_orange = False
        self.BW_bed_blue = False
        self.BW_bed_green = False
        self.BW_bed_purple = False

        self.tick_iron_ingot = 0
        self.tick_gold_ingot = 0
        self.tick_diamond = 0
        self.tick_emerald = 0

        self.guanzhanPlayer = []
        self.match_switch = False
        self.event_index_all = 0
        self.win_team = ""

        self.bedwar_teamslist_blue_id = []
        self.bedwar_teamslist_green_id = []
        self.bedwar_teamslist_orange_id = []
        self.bedwar_teamslist_purple_id = []

        self.bedwar_player_list = []
        self.dead_list = []
        self.BW_match_playerlist = []
        self.BW_aev_playerlist = []
        self.playerlist_new = []

        self.bedwar_switch = False  # 起床战争比赛开关
        self.bedwar_times = 0  # 起床战争总计时

        self.recover_tp_team = ""
        self.recover_tp_id = 0
        self.recover_status_id = 0

        self.fix_y = 115

        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand('/clear @a', False)
        comp.SetCommand('/effect @a clear', False)
        comp.SetCommand('/title @a title §c游戏正在重置！', False)
        comp.SetCommand('/kill @e[type=minecraft:ender_dragon]', False)
        comp.SetCommand('/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> §c游戏正在重置！"}]}', False)

        for c in self.playerlist:
            comp = serverApi.GetEngineCompFactory().CreateName(c['id'])
            comp.SetPlayerPrefixAndSuffixName("", serverApi.GenerateColor('RED'), '', serverApi.GenerateColor('RED'))

        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())

        self.restart_piaofu()

        self.bedwar_restart = True

        self.TIME_LATER_FUN("block_fix", 2)
        self.TIME_LATER_FUN("effect_clear", 3)
        self.TIME_LATER_FUN("fly_check", 4)
        self.TIME_LATER_FUN("clear_all", 5)
        self.TIME_LATER_FUN("switch_fa_eff", 6)

    # 清理地面物品
    def clear_all(self):
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand('/kill @e[type=item]', False)

    # 检查玩家飞行模式
    def fly_check(self):

        for p in self.playerlist:
            playerid = p['id']
            nickname = p['name']
            comp = serverApi.GetEngineCompFactory().CreateFly(playerid)
            comp.ChangePlayerFlyState(False)

            comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            comp.SetCommand("/effect @s instant_health 99999 255 true", playerid, False)

            comp = serverApi.GetEngineCompFactory().CreatePlayer(playerid)
            suc = comp.SetPlayerRespawnPos((-91, 108, -124), 0)

    # 地面物品检测
    def res_cr_safe(self):
        print "=== res_cr_safe"
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand('/testfor @e[type=item]', None, False)

    # 重置游戏-漂浮效果
    def restart_piaofu(self):
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand('/effect @a levitation 9999 1 true', None, False)

    # 床检测
    def check_bed(self):
        print ("bed status", self.BW_bed_blue, self.BW_bed_orange, self.BW_bed_green, self.BW_bed_purple)

    # 延迟事件
    def TIME_LATER_FUN(self, EVENT_NAME, TIME):
        TIME_D = time.time() + TIME
        time_later = {"EVENT_NAME": EVENT_NAME,
                      "DEAD_TIME": TIME_D,
                      "START_TIME": time.time()}
        self.time_laters.append(time_later)

    # 重置游戏-传送到大厅
    def restart_tp(self):
        if self.bedwar_restart == True:
            self.bedwar_restart = False
            for p in self.playerlist:
                playerid = p['id']
                nickname = p['name']

                comp = serverApi.GetEngineCompFactory().CreateName(playerid)
                comp.SetPlayerPrefixAndSuffixName("", serverApi.GenerateColor('RED'), '',
                                                  serverApi.GenerateColor('RED'))

                comp = serverApi.GetEngineCompFactory().CreateDimension(playerid)
                comp.ChangePlayerDimension(0, (-112, 120, -138))

            comp = serverApi.GetEngineCompFactory().CreateBlockInfo(self.playerlist[0]['id'])
            pos = (-112, 105, -136)
            dimensionId = 0
            suc = comp.SetSignBlockText(pos, "§e§l✔✔✔\n§c§l【游戏可加入】\n§d§l请尽快匹配！", dimensionId)

        self.TIME_LATER_FUN("notice_all_restart", 2)

    # 游戏开始
    def BW_game_start(self):

        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand('/effect @a clear', False)

        self.bedwar_switch = True
        self.BW_bed_green = True
        self.BW_bed_purple = True
        self.BW_bed_orange = True
        self.BW_bed_blue = True

        comp = serverApi.GetEngineCompFactory().CreateBlockInfo(self.playerlist[0]['id'])
        pos = (-112, 105, -136)
        dimensionId = 0
        suc = comp.SetSignBlockText(pos, "§c§l【游戏已开始】\n§d§l请等待下一轮或观战", dimensionId)

        # comp = serverApi.GetEngineCompFactory().CreateChunkSource(serverApi.GetLevelId())
        # comp.SetAddArea('THE0END', 2, (-1500, 0, -1500), (1500, 0, 1500))

        # for e in self.BW_aev_playerlist:
        #     comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        #     comp.SetCommand('/kill ', e, False)

    # 游戏右侧信息栏-大厅
    def BW_notice_wait(self, ver, player_now, player_match):
        notice_player_reset = '/scoreboard players reset * game'
        notice_ob_remove = "/scoreboard objectives remove game"
        notice_ob_add = "/scoreboard objectives add game dummy §l§5起床战争:末地龙魂"
        notice_ob_set = "/scoreboard objectives setdisplay sidebar game"
        notice_player_tips_9 = '/scoreboard players set "§7[v' + str(ver) + '] " game 9'
        notice_player_tips_8 = '/scoreboard players set "§e当前人数§3' + str(player_match) + '/' + str(
            player_now) + '§e人 " game 8'
        notice_player_tips_7 = '/scoreboard players set "§a请穿戴金胸甲匹配... " game 7'
        if self.match_switch == True:
            notice_player_tips_6 = '/scoreboard players set "§3游戏还剩 §l§3' + str(self.match_scends) + '秒 §3开始 " game 6'
        else:
            notice_player_tips_6 = '/scoreboard players set "§3匹配满2人后自动开始游戏 " game 6'
        notice_player_tips_5 = '/scoreboard players set "§c本图作者：我是初云工作室 " game 5'
        notice_player_tips_4 = '/scoreboard players set "§d企鹅交流群↓↓↓ " game 4'
        notice_player_tips_3 = '/scoreboard players set "§d881304734 " game 3'
        notice_player_tips_2 = '/scoreboard players set "§6初云杯大赛已开始报名！ " game 2'
        notice_player_tips_1 = '/scoreboard players set "§l§c欢迎反馈违规用户！ " game 1'

        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand(notice_player_reset, False)
        # comp.SetCommand(notice_ob_remove, False)
        comp.SetCommand(notice_ob_add, False)
        comp.SetCommand(notice_ob_set, False)
        comp.SetCommand(notice_player_tips_9, False)
        comp.SetCommand(notice_player_tips_8, False)
        comp.SetCommand(notice_player_tips_7, False)
        comp.SetCommand(notice_player_tips_6, False)
        comp.SetCommand(notice_player_tips_5, False)
        comp.SetCommand(notice_player_tips_4, False)
        comp.SetCommand(notice_player_tips_3, False)
        comp.SetCommand(notice_player_tips_2, False)
        comp.SetCommand(notice_player_tips_1, False)

    # 游戏右侧信息栏-游戏开始
    def BW_notice_game_start(self, ver):
        notice_player_reset = '/scoreboard players reset * game'
        notice_ob_remove = "/scoreboard objectives remove game"
        notice_ob_add = "/scoreboard objectives add game dummy §l§5起床战争:末地龙魂"
        notice_ob_set = "/scoreboard objectives setdisplay sidebar game"
        # notice_min = self.bedwar_times/60
        # notice_sec = self.bedwar_times - notice_min*60
        # if notice_sec<=9:
        #     notice_sec_str = "0"+str(notice_sec)
        # else:
        #     notice_sec_str = str(notice_sec)
        # notice_player_tips_99 = '/scoreboard players set "§7[v'+str(ver)+'] - '+str(notice_min)+':'+str(notice_sec_str)+'" game 99'
        notice_player_tips_98 = '/scoreboard players set "§f各队情况： " game 97'
        notice_player_tips_97 = '/scoreboard players set "§f " game 96'

        if self.BW_bed_orange == True:

            if len(self.bedwar_teamslist_orange_id) <= 0:
                notice_player_tips_96 = '/scoreboard players set "  §6橙队 §c✔ " game 95'
            else:
                notice_player_tips_96 = '/scoreboard players set "  §6橙队 §a✔ " game 95'
        if self.BW_bed_blue == True:
            if len(self.bedwar_teamslist_blue_id) <= 0:
                notice_player_tips_95 = '/scoreboard players set "  §3蓝队 §c✔ " game 94'
            else:
                notice_player_tips_95 = '/scoreboard players set "  §3蓝队 §a✔ " game 94'
        if self.BW_bed_purple == True:
            if len(self.bedwar_teamslist_purple_id) <= 0:
                notice_player_tips_94 = '/scoreboard players set "  §9紫队 §c✔ " game 93'
            else:
                notice_player_tips_94 = '/scoreboard players set "  §9紫队 §a✔ " game 93'
        if self.BW_bed_green == True:
            if len(self.bedwar_teamslist_green_id) <= 0:
                notice_player_tips_93 = '/scoreboard players set "  §a绿队 §c✔ " game 92'
            else:
                notice_player_tips_93 = '/scoreboard players set "  §a绿队 §a✔ " game 92'

        if self.BW_bed_orange == False:
            if len(self.bedwar_teamslist_orange_id) <= 0:
                notice_player_tips_96 = '/scoreboard players set "  §6橙队 §c✖ " game 95'
            else:
                notice_player_tips_96 = '/scoreboard players set "  §6橙队 §f' + str(
                    len(self.bedwar_teamslist_orange_id)) + ' " game 95'

        if self.BW_bed_blue == False:
            if len(self.bedwar_teamslist_blue_id) <= 0:
                notice_player_tips_95 = '/scoreboard players set "  §3蓝队 §c✖ " game 94'
            else:
                notice_player_tips_95 = '/scoreboard players set "  §3蓝队 §f' + str(
                    len(self.bedwar_teamslist_blue_id)) + ' " game 94'

        if self.BW_bed_purple == False:
            if len(self.bedwar_teamslist_purple_id) <= 0:
                notice_player_tips_94 = '/scoreboard players set "  §9紫队 §c✖ " game 93'
            else:
                notice_player_tips_94 = '/scoreboard players set "  §9紫队 §f' + str(
                    len(self.bedwar_teamslist_purple_id)) + ' " game 93'

        if self.BW_bed_green == False:
            if len(self.bedwar_teamslist_green_id) <= 0:
                notice_player_tips_93 = '/scoreboard players set "  §a绿队 §c✖ " game 92'
            else:
                notice_player_tips_93 = '/scoreboard players set "  §a绿队 §f' + str(
                    len(self.bedwar_teamslist_green_id)) + ' " game 92'

        notice_player_tips_92 = '/scoreboard players set "§c " game 91'
        notice_player_tips_91 = '/scoreboard players set "§5感谢下载游玩Thanks(*^▽^*) " game 90'
        notice_player_tips_90 = '/scoreboard players set "§c本图作者：我是初云工作室 " game 89'
        # notice_player_tips_89 = '/scoreboard players set "§d企鹅交流群↓↓↓ " game 89'
        # notice_player_tips_88 = '/scoreboard players set "§d881304734 " game 88'
        # notice_player_tips_87 = '/scoreboard players set "§6初云杯大赛已开始报名！ " game 87'
        # notice_player_tips_86 = '/scoreboard players set "§l§c欢迎反馈违规用户！ " game 86'

        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand(notice_player_reset, False)
        # comp.SetCommand(notice_ob_remove, False)
        comp.SetCommand(notice_ob_add, False)
        comp.SetCommand(notice_ob_set, False)
        # comp.SetCommand(notice_player_tips_99, False)
        comp.SetCommand(notice_player_tips_98, False)
        comp.SetCommand(notice_player_tips_97, False)
        comp.SetCommand(notice_player_tips_96, False)
        comp.SetCommand(notice_player_tips_95, False)
        comp.SetCommand(notice_player_tips_94, False)
        comp.SetCommand(notice_player_tips_93, False)
        comp.SetCommand(notice_player_tips_92, False)
        comp.SetCommand(notice_player_tips_91, False)
        comp.SetCommand(notice_player_tips_90, False)
        # comp.SetCommand(notice_player_tips_89, False)
        # comp.SetCommand(notice_player_tips_88, False)
        # comp.SetCommand(notice_player_tips_87, False)
        # comp.SetCommand(notice_player_tips_86, False)

        self.BW_notice_game_start_time()

    # 游戏右侧信息栏-游戏开始-总时间
    def BW_notice_game_start_time(self):
        if self.bedwar_switch == True:
            notice_min = self.bedwar_times / 60
            notice_sec = self.bedwar_times - notice_min * 60
            notice_min = 29 - notice_min
            notice_sec = 60 - notice_sec
            if notice_sec <= 9:
                notice_sec_str = "0" + str(notice_sec)
            else:
                notice_sec_str = str(notice_sec)

            notice_player_tips_99 = '/scoreboard players set "§7[v' + str(self.ver) + '] - ' + str(
                notice_min) + ':' + str(
                notice_sec_str) + '" game 99'

            self.game_event()

            comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            comp.SetCommand(notice_player_tips_99, False)

    # 末影龙召唤
    def dr_sum(self):
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand("/kill @e[type=minecraft:ender_dragon]", False)
        com = "/summon ender_dragon 0 90 0"

        comp.SetCommand(com, False)
        comp.SetCommand("/title @a subtitle §e击败可得全队鞘翅", False)
        comp.SetCommand("/title @a title §5末影龙已生成！", False)

    # 游戏内事件
    def game_event(self):
        if self.bedwar_switch == True:
            event_name = ""
            event_index = self.bedwar_times / 200 - 1

            if event_index == -1:
                event_name = "全体速度加成"

            if event_index == 0:
                event_name = "第一波末影龙刷新"
                if self.event_index_all == event_index:
                    self.event_index_all += 1
                    self.event_all_speed = True
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    com = "/effect @a speed 9999 1 true"
                    comp.SetCommand(com, False)
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    comp.SetCommand("/title @a title §c全体速度加成！", False)

            if event_index == 1:
                event_name = "全体跳跃加成"

                if self.event_index_all == event_index:
                    self.event_index_all += 1
                    self.dr_sum()

            if event_index == 2:
                event_name = "第二波末影龙刷新"
                if self.event_index_all == event_index:
                    self.event_index_all += 1
                    self.event_all_jump = True
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    com = "/effect @a jump_boost 9999 1 true"
                    comp.SetCommand(com, False)
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    comp.SetCommand("/title @a title §c全体跳跃加成！", False)

            if event_index == 3:
                event_name = "全体力量加成"
                if self.event_index_all == event_index:
                    self.event_index_all += 1
                    self.dr_sum()

            if event_index == 4:
                event_name = "第三波末影龙刷新"
                if self.event_index_all == event_index:
                    self.event_index_all += 1
                    self.event_all_power = True
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    com = "/effect @a strength 9999 1 true"
                    comp.SetCommand(com, False)
                    comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                    comp.SetCommand("/title @a title §c全体力量加成！", False)

            if event_index == 5:
                event_name = "所有床自毁并缩圈"
                if self.event_index_all == event_index:
                    self.event_index_all += 1
                    self.dr_sum()

            if event_index == 6:
                event_name = "所有人随机传送"
                if self.event_index_all == event_index:
                    self.event_index_all += 1
                    self.bed_boom_suo()

            if event_index == 7:
                event_name = "游戏结束"
                if self.event_index_all == event_index:
                    self.event_index_all += 1
                    self.all_tp()

            event_sec_c = (event_index + 2) * 200 - self.bedwar_times

            if event_sec_c > 10:
                notice_player_tips_98 = '/scoreboard players set "§f' + event_name + '倒计时： §a' + str(
                    event_sec_c) + '秒' + ' " game 98'
            else:
                notice_player_tips_98 = '/scoreboard players set "§f' + event_name + '倒计时： §c' + str(
                    event_sec_c) + '秒' + ' " game 98'

            comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            comp.SetCommand(notice_player_tips_98, False)

    # 床自毁
    def bed_boom_suo(self):
        self.BW_bed_blue = False
        self.BW_bed_orange = False
        self.BW_bed_purple = False
        self.BW_bed_green = False

        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand("/title @a subtitle §e请前往中心区（龙池）", False)
        comp.SetCommand("/title @a title §c床已自毁，开始缩圈！", False)
        comp.SetCommand("/fill 104 67 129 104 67 129 air", False)  # 紫床
        comp.SetCommand("/fill -85 67 126 -85 67 126 air", False)  # 蓝床
        comp.SetCommand("/fill 109 69 -125 109 69 -125 air", False)  # 橙床
        comp.SetCommand("/fill -75 67 -129 -75 67 -129 air", False)  # 绿床

        self.suoquan_sw = True

    # 随机传送
    def all_tp(self):

        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand("/title @a subtitle §e倒计时10秒", False)
        comp.SetCommand("/title @a title §c开始随机传送！", False)
        self.TIME_LATER_FUN("all_tp_e", 10)

    # 原本设定分散传送（传送到一起的不同队伍）
    def all_tp_e(self):
        # 原本设定分散传送（传送到一起的不同队伍）

        team_now_id = []

        for e in self.bedwar_teamslist_blue_id:
            team_now_id.append(e)
        for e in self.bedwar_teamslist_purple_id:
            team_now_id.append(e)
        for e in self.bedwar_teamslist_green_id:
            team_now_id.append(e)
        for e in self.bedwar_teamslist_orange_id:
            team_now_id.append(e)

        ran_c = random.randint(0, len(team_now_id) - 1)

        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand("/tp @a @s", team_now_id[ran_c], False)

    # 复活-复合传送
    def recover_tp(self):

        print ("===== 复合传送" + self.recover_tp_team)
        comp = serverApi.GetEngineCompFactory().CreateDimension(self.recover_tp_id)
        if self.recover_tp_team == "紫之队":
            comp.ChangePlayerDimension(2, (91, 68, 140))
        if self.recover_tp_team == "绿之队":
            comp.ChangePlayerDimension(2, (-62, 68, -139))
        if self.recover_tp_team == "蓝之队":
            comp.ChangePlayerDimension(2, (-98, 68, 137))
        if self.recover_tp_team == "橙之队":
            comp.ChangePlayerDimension(2, (96, 70, -136))

    # 复活-状态
    def recover_status(self):
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())

        comp.SetCommand('/tellraw @s {"rawtext": [{"text": "§l§e起床战争>> §4你获得5秒钟无敌时间"}]}', self.recover_status_id, False)

        comp.SetCommand("/effect @s instant_health 5 255 true", self.recover_status_id, False)

        if self.event_all_jump == True:
            com = "/effect @s jump_boost 9999 1 true"
            comp.SetCommand(com, self.recover_status_id, False)
        if self.event_all_speed == True:
            com = "/effect @s speed 9999 1 true"
            comp.SetCommand(com, self.recover_status_id, False)
        if self.event_all_power == True:
            com = "/effect @s strength 9999 1 true"
            comp.SetCommand(com, self.recover_status_id, False)
        comp = serverApi.GetEngineCompFactory().CreateFly(self.recover_status_id)
        comp.ChangePlayerFlyState(False)
        comp = serverApi.GetEngineCompFactory().CreatePlayer(self.recover_status_id)
        comp.SetPlayerGameType(serverApi.GetMinecraftEnum().GameType.Survival)

    # 隐身
    def hide_c(self):
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand('/effect @s invisibility 9999 255 true', self.hide_id, False)
        comp.SetCommand('/effect @s instant_health 9999 255 true', self.hide_id, False)
        comp.SetCommand('/effect @s weakness 99999 255 true', self.hide_id, False)
        comp.SetCommand('/effect @s instant_health 99999 255 true', self.hide_id, False)

    # 效果清除
    def effect_clear(self):
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand('/effect @a clear', False)

    # 玩家颜色盔甲
    def player_main(self):
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        for e in self.bedwar_teamslist_blue_id:
            comp = serverApi.GetEngineCompFactory().CreateItem(e)
            data = comp.GetPlayerItem(3, 1)
            if data != None:
                newItemName = data['newItemName']
            else:
                newItemName = ''
            if newItemName != 'minecraft:elytra':
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                com = "/replaceitem entity @s slot.armor.chest 0 kssae:blue_team_armor_main"
                comp.SetCommand(com, e, False)
        for e in self.bedwar_teamslist_orange_id:
            comp = serverApi.GetEngineCompFactory().CreateItem(e)
            data = comp.GetPlayerItem(3, 1)
            if data != None:
                newItemName = data['newItemName']
            else:
                newItemName = ''
            if newItemName != 'minecraft:elytra':
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                com = "/replaceitem entity @s slot.armor.chest 0 kssae:orange_team_armor_main"
                comp.SetCommand(com, e, False)
        for e in self.bedwar_teamslist_purple_id:
            comp = serverApi.GetEngineCompFactory().CreateItem(e)
            data = comp.GetPlayerItem(3, 1)
            if data != None:
                newItemName = data['newItemName']
            else:
                newItemName = ''
            if newItemName != 'minecraft:elytra':
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                com = "/replaceitem entity @s slot.armor.chest 0 kssae:purple_team_armor_main"
                comp.SetCommand(com, e, False)
        for e in self.bedwar_teamslist_green_id:
            comp = serverApi.GetEngineCompFactory().CreateItem(e)
            data = comp.GetPlayerItem(3, 1)
            if data != None:
                newItemName = data['newItemName']
            else:
                newItemName = ''
            if newItemName != 'minecraft:elytra':
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                com = "/replaceitem entity @s slot.armor.chest 0 kssae:green_team_armor_main"
                comp.SetCommand(com, e, False)

    # 检查游戏结束
    def check_game_over(self):
        if self.bedwar_switch == True:
            team_green_num = len(self.bedwar_teamslist_green_id)
            team_orange_num = len(self.bedwar_teamslist_orange_id)
            team_blue_num = len(self.bedwar_teamslist_blue_id)
            team_purple_num = len(self.bedwar_teamslist_purple_id)
            team_win = 0
            if team_green_num >= 1:
                team_green_win = True
                team_win += 1

            if team_orange_num >= 1:
                team_orange_win = True
                team_win += 1

            if team_blue_num >= 1:
                team_blue_win = True
                team_win += 1

            if team_purple_num >= 1:
                team_purple_win = True
                team_win += 1

            team_all_num = team_green_num + team_orange_num + team_blue_num + team_purple_num

            if team_win <= 1:
                self.bedwar_switch = False
                self.game_over()
            elif self.bedwar_times >= 1800:
                self.bedwar_switch = False
                self.game_over()

    # 游戏结束
    def game_over(self):
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand('/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> §e游戏结束，正在结算！"}]}', False)
        self.suoquan_sw = False
        comp.SetCommand("/title @a subtitle §c§l正在结算中", False)
        comp.SetCommand("/title @a title §e§l游戏结束！", False)
        self.TIME_LATER_FUN("game_over_count", 4)

    # 游戏结束-结算
    def game_over_count(self):
        team_green_num = len(self.bedwar_teamslist_green_id)
        team_orange_num = len(self.bedwar_teamslist_orange_id)
        team_blue_num = len(self.bedwar_teamslist_blue_id)
        team_purple_num = len(self.bedwar_teamslist_purple_id)
        team_win = 0
        team_green_win = False
        team_orange_win = False
        team_blue_win = False
        team_purple_win = False
        if team_green_num >= 1:
            team_green_win = True
            team_win += 1

        if team_orange_num >= 1:
            team_orange_win = True
            team_win += 1

        if team_blue_num >= 1:
            team_blue_win = True
            team_win += 1

        if team_purple_num >= 1:
            team_purple_win = True
            team_win += 1

        team_all_num = team_green_num + team_orange_num + team_blue_num + team_purple_num

        if team_win >= 2 or team_win < 1:
            comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            comp.SetCommand('/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> §3游戏结算成功：§e本局游戏平局！"}]}', False)
            comp.SetCommand("/title @a subtitle §c§l没有队伍获得胜利", False)
            comp.SetCommand("/title @a title §e§l本局游戏平局！", False)
            self.TIME_LATER_FUN("game_over_cz", 4)
        else:
            comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            if team_green_win == True:
                team_name = "绿之队"
                team_color = "§a"
                team_len = team_green_num
                self.win_team = team_name
            if team_orange_win == True:
                team_name = "橙之队"
                team_color = "§6"
                team_len = team_orange_num
                self.win_team = team_name
            if team_blue_num == True:
                team_name = "蓝之队"
                team_color = "§3"
                team_len = team_blue_num
                self.win_team = team_name
            if team_purple_num == True:
                team_name = "紫之队"
                team_color = "§9"
                team_len = team_purple_num
                self.win_team = team_name

            team_all = team_color + team_name
            comp.SetCommand('/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> §3游戏结算成功：§e恭喜 ' + team_all + ' §e获得胜利！"}]}',
                            False)
            comp.SetCommand("/title @a subtitle §3§l剩余人数：" + str(team_len) + "人", False)
            comp.SetCommand("/title @a title §e§l恭喜 " + team_all + " §e获得胜利！", False)
            self.TIME_LATER_FUN("game_over_add", 4)

    # 游戏结束-加积分
    def game_over_add(self):
        print ("开始加积分")

        self.TIME_LATER_FUN("game_over_cz", 4)

    # 游戏结束-重置
    def game_over_cz(self):

        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand('/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> §c游戏即将重置！"}]}', False)
        comp.SetCommand("/title @a title §c§l游戏即将重置！", False)

        self.TIME_LATER_FUN("restart", 4)

    # 地形修复
    def block_fix(self):
        temp_1_x = -126
        temp_1_z = 172
        temp_2_x = 124
        temp_2_z = -149

        comp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId())
        temp = (-126, 7, -149)

        status = comp.PlaceStructure(None, temp, "kssae:end_2", 2, 0)
        print ("### end_fix", status)

        self.TIME_LATER_FUN("fix_more_p_b", 10)

        self.TIME_LATER_FUN("restart_tp", 12)

    # 游戏结束-游戏重置成功
    def notice_all_restart(self):
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand('/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> §e游戏重置成功！"}]}', False)
        comp.SetCommand("/title @a title §e§l游戏重置成功！", False)

    # 地形修复-额外
    def fix_more_p_b(self):
        comp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId())
        temp = (-110, 59, 111)

        status = comp.PlaceStructure(None, temp, "kssae:blue_2", 2, 0)
        print ("### blue_home_fix", status)

        comp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId())
        temp = (78, 59, 114)

        status = comp.PlaceStructure(None, temp, "kssae:purple_2", 2, 0)
        print ("### purple_home_fix", status)

        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand('/tellraw @a {"rawtext": [{"text": "§l§e起床战争>> §d地图重置成功！"}]}', False)
        comp.SetCommand("/title @a title §d§l地图重置成功！", False)

    # 观战效果
    def aev_effect(self):
        if self.bedwar_switch == True:
            for e in self.BW_aev_playerlist:
                comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
                comp.SetCommand('/effect @s invisibility 9999 255 true', e, False)
                comp.SetCommand('/effect @s instant_health 9999 255 true', e, False)
                comp.SetCommand('/effect @s weakness 99999 255 true', e, False)
                comp.SetCommand('/effect @s instant_health 99999 255 true', e, False)

    # 观战传送
    def aev_tp(self):
        for e in self.BW_aev_playerlist:
            comp = serverApi.GetEngineCompFactory().CreatePlayer(e)
            suc = comp.SetPlayerRespawnPos((0, 80, 0), 2)
            comp = serverApi.GetEngineCompFactory().CreateDimension(e)
            comp.ChangePlayerDimension(2, (0, 80, 0))
            comp = serverApi.GetEngineCompFactory().CreateFly(e)
            comp.ChangePlayerFlyState(True)
            # comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
            # comp.SetCommand('/gamemode a', e, False)
            comp = serverApi.GetEngineCompFactory().CreatePlayer(e)
            comp.SetPlayerGameType(serverApi.GetMinecraftEnum().GameType.Adventure)

    # 废弃
    def kill_all_su(self):
        print ("###kill_all_su")
        # comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        # comp.SetCommand('/summon kssae:entity 96 70 139', False)
        # comp.SetCommand('/summon kssae:entity -92 70 136', False)
        # comp.SetCommand('/summon kssae:entity -66 70 -138', False)
        # comp.SetCommand('/summon kssae:entity 91 70 -134', False)
        #
        # comp.SetCommand('/summon kssae:entity_1 86 70 139', False)
        # comp.SetCommand('/summon kssae:entity_1 -102 70 138', False)
        # comp.SetCommand('/summon kssae:entity_1 -56 70 -140', False)
        # comp.SetCommand('/summon kssae:entity_1 101 70 -136', False)
        #
        # comp.SetCommand('/summon kssae:entity_2 -92 70 138', False)
        # comp.SetCommand('/summon kssae:entity_3 -66 70 -140', False)
        # comp.SetCommand('/summon kssae:entity_4 91 70 -136', False)
        # comp.SetCommand('/summon kssae:entity_5 96 70 141', False)

    # 废弃
    def kill_all_kill(self):

        print ("###kill_all_kill")
        # comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        # comp.SetCommand('/kill @e[type=kssae:entity]', False)
        # comp.SetCommand('/kill @e[type=kssae:entity_1]', False)
        # comp.SetCommand('/kill @e[type=kssae:entity_2]', False)
        # comp.SetCommand('/kill @e[type=kssae:entity_3]', False)
        # comp.SetCommand('/kill @e[type=kssae:entity_4]', False)
        # comp.SetCommand('/kill @e[type=kssae:entity_5]', False)
        #
        # self.TIME_LATER_FUN("kill_all_su", 1)

    # 重置游戏-卡顿提醒
    def switch_fa_eff(self):
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand('/effect @a clear', False)
        for item in self.playerlist:
            comp = serverApi.GetEngineCompFactory().CreateFly(item['id'])
            comp.ChangePlayerFlyState(False)
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        # comp.SetCommand('/gamemode a @a', False)

        for gc in self.playerlist:
            comp = serverApi.GetEngineCompFactory().CreatePlayer(gc['id'])
            comp.SetPlayerGameType(serverApi.GetMinecraftEnum().GameType.Adventure)

        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand('/title @a title §e§l可能卡顿请稍等！', False)
        self.TIME_LATER_FUN("switch_fa_eff_health", 1)

    # 重置游戏-无限生命状态
    def switch_fa_eff_health(self):
        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand('/effect @a instant_health 99999 255 true', False)

    # 缩圈
    def suoquan(self):

        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())

        r = self.suoquan_r
        if self.suoquan_r > 6:
            self.suoquan_r -= 1
        comp.SetCommand('/effect @a[m=0] fatal_poison 99999 1', True)
        print ("###suoquan", str(r / 2 - 1))
        comp.SetCommand("/effect @a[m=0,x=0,z=0,dx=" + str(r / 2) + ",dz=" + str(r / 2) + "] fatal_poison 0 0", True)
        comp.SetCommand("/effect @a[m=0,x=0,z=0,dx=-" + str(r / 2) + ",dz=-" + str(r / 2) + "] fatal_poison 0 0", True)
        comp.SetCommand("/effect @a[m=0,x=0,z=0,dx=" + str(r / 2) + ",dz=-" + str(r / 2) + "] fatal_poison 0 0", True)
        comp.SetCommand("/effect @a[m=0,x=0,z=0,dx=-" + str(r / 2) + ",dz=" + str(r / 2) + "] fatal_poison 0 0", True)
        i = 0
        while i < r:
            # print("### lizi_test_x_a", i)
            i += 1
            d = r / 2

            a_1_x = -d
            a_1_y = -d
            b_1_x = d
            b_1_y = d

            e = a_1_x + i

            if e & 1 == 0:
                comp.SetCommand('/particle minecraft:basic_flame_particle ' + str(e) + ' 70 ' + str(d), False)
        i = 0
        while i < r:
            # print("### lizi_test_y_a", i)
            i += 1
            d = r / 2

            a_1_x = -d
            a_1_y = -d
            b_1_x = d
            b_1_y = d

            e = b_1_y - i
            if e & 1 == 0:
                comp.SetCommand('/particle minecraft:basic_flame_particle ' + str(d) + ' 70 ' + str(e), False)
        i = 0
        while i < r:
            # print("### lizi_test_x_b", i)
            i += 1
            d = r / 2

            a_1_x = -d
            a_1_y = -d
            b_1_x = d
            b_1_y = d

            e = a_1_y + i
            if e & 1 == 0:
                comp.SetCommand('/particle minecraft:basic_flame_particle ' + str(e) + ' 70 ' + str(-d), False)
        i = 0
        while i < r:
            # print("### lizi_test_y_b", i)
            i += 1
            d = r / 2

            a_1_x = -d
            a_1_y = -d
            b_1_x = d
            b_1_y = d

            e = b_1_x - i
            if e & 1 == 0:
                comp.SetCommand('/particle minecraft:basic_flame_particle ' + str(-d) + ' 70 ' + str(e), False)

    # 队伍分配匹配
    def assign_teams(self,players, num_teams):
        random.shuffle(players)

        sorted_players = players
        teams = [[] for _ in range(num_teams)]
        teams[0].append(sorted_players[0])
        for player in sorted_players[1:]:
            min_team = min(teams, key=len)
            min_team.append(player)
        return teams

    # 搭桥蛋
    def egg_road(self):

        comp = serverApi.GetEngineCompFactory().CreateCommand(serverApi.GetLevelId())
        comp.SetCommand("/execute @e[type=egg] ^^^-2 fill ~1 ~0 ~0 ~0 ~0 ~-1 wool 0 replace air", True)

    def mingxie(self):
        comp = serverApi.GetEngineCompFactory().CreateBlockInfo(self.playerlist[0]['id'])
        list_lib =[
            ["我是恋_古明地恋","BUG建议和内测","超管"],
            ["和气的古都天蓬","地图灵感和技术帮助","《起床战争：沙漠》\n§c§l地图作者"],
            ["长生建筑师", "建筑指令和内测", "超管"],
            ["卧室笑柯哀", "内测和BUG修复建议", "超管"],
            ["小周WATE", "内测", "铁粉"],
            ["铁板高光", "内测", "工作室原始成员"],
            ["吴光胜的李子追番", "内测和BUG修复建议", "铁粉"],
            ["史蒂夫125436", "内测和BUG修复建议", "超能玩家"],
            ["苦瓜要指令", "内测和BUG修复建议", "超管"],
            ["大力出奇迹8572", "内测和玩法建议", "工作室原始成员"]
        ]
        # pos = (-117, 109, -141)
        # pos = (-117, 104, -131)
        # pos = (-117, 104, -140)
        range_109 = [-131,-132,-133,-134,-135,-136,-137,-138,-139,-140,-141]
        range_104 = range(104,110)
        for i in range_104:
            for e in range_109:

                pos = (-117, i, e)
                print pos
                try:
                    suc = comp.SetSignBlockText(pos, "§e§l{}\n§d§l{}\n§c§l{}".format(list_lib[0][0],list_lib[0][1],list_lib[0][2]), 0)
                    if suc==True:
                        list_lib.remove(list_lib[0])
                except:
                    pass